在pathFor iron-router中使用当前查询中的每个数据

时间:2015-03-19 21:43:31

标签: javascript node.js meteor url-routing

刚刚开始使用meteor,我尝试使用iron-router进行路由。这是我的数据结构

team
  _id
  name
  tags:[{name,counter}]

以下是我尝试在模板

中使用的链接
{{#each team.tags}}
   <a href="{{ pathFor 'team' _id=../team._id query='search='+this.name }}">{{this.name}} <span class="count-list">{{this.counter}}</span></a> 
{{/each}}

我的路由器有:

route('/team/:_id')  // And I get the search through the GET property... this.params.query 

但它不喜欢query='search='+this.name,我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

因为它是GET方法,所以这应该有效:

{{#each team.tags}}
   <a href="{{ pathFor 'team' _id=../team._id}}/?search={{this.name}}">{{this.name}} <span class="count-list">{{this.counter}}</span></a> 
{{/each}}

否则,您必须在帮助程序的前端(或registerHelper函数)中构建URL,因为空格键不允许复合操作。