Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Meteor中的模板文件访问URL参数?_Meteor - Fatal编程技术网

如何从Meteor中的模板文件访问URL参数?

如何从Meteor中的模板文件访问URL参数?,meteor,Meteor,我正在使用Iron Router,我想从URL获取参数,并将其放置在模板文件中。例如: 在我的模板文件中: <template name="category_products"> <p>Sorry, there are no _____ products.</p> </template> 我想用电子器件来代替,这样输出就会 对不起,没有电子产品 假设已定义路由,则可以使用this.params获取参数。还可以为模板提供数据上下文,该数据

我正在使用Iron Router,我想从URL获取参数,并将其放置在模板文件中。例如:

在我的模板文件中:

<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>