如何从Meteor中的模板文件访问URL参数?
我正在使用Iron Router,我想从URL获取参数,并将其放置在模板文件中。例如: 在我的模板文件中:如何从Meteor中的模板文件访问URL参数?,meteor,Meteor,我正在使用Iron Router,我想从URL获取参数,并将其放置在模板文件中。例如: 在我的模板文件中: <template name="category_products"> <p>Sorry, there are no _____ products.</p> </template> 我想用电子器件来代替,这样输出就会 对不起,没有电子产品 假设已定义路由,则可以使用this.params获取参数。还可以为模板提供数据上下文,该数据
<template name="category_products">
<p>Sorry, there are no _____ products.</p>
</template>
我想用电子器件来代替,这样输出就会
对不起,没有电子产品
假设已定义路由,则可以使用this.params获取参数。还可以为模板提供数据上下文,该数据上下文是包含多个键的对象:
Router.route('/categories/:name',()=>{
this.render('category_products', {
data: function () {
return {
cursor: Products.find({categoryName: this.params.name}),
category: this.params.name
};
}
});
});
html:
<template name="category_products">
{{#if cursor.count()}}
{{#each cursor}}
{{name}}
{{/each}}
{{else}}
<p>Sorry, there are no {{category}} products.</p>
{{/endif}}
</template>