【问题标题】:iron-router, array of strings and pathFor铁路由器,字符串数组和路径
【发布时间】:2014-05-10 04:20:15
【问题描述】:

我有以下代码:

<ul>
{{#each title}}
    <li><a href="{{pathFor 'tplTitle'}}">{{this}}</a></li>
{{/each}}
</ul>

"title" 是一个字符串数组:["A title","Another title","End title"]

路由器的代码:

this.route("tplTitle", {
    path:"/title/:sometitle",
    data: function(){
       return [... a search using "sometitle" argument ...]
    })

问题:{{pathFor 'tplTitle'}} 返回一个空字符串,即使我输入了路径:“/title/:this”(这很奇怪,但可能有效:P)。

在文档中,我找不到关于 pathFor 的这个问题的信息 :(

我该怎么做?

- 编辑-

我找到了这个解决方案:

<li><a href="{{pathFor 'article' _id=this._id }}">{{title}}</a></li>

来源:How to pass a parameter to pathFor in Handlebars for Iron-Router with Meteorite?

而且它有效!但它的这个解决方案优雅吗?

【问题讨论】:

    标签: string meteor iron-router


    【解决方案1】:

    我觉得不错。每https://github.com/EventedMind/iron-router/blob/master/lib/client/ui/helpers.js#L42

    /**
     * Example Use:
     *
     *  {{pathFor 'items' params=this}}
     *  {{pathFor 'items' id=5 query="view=all" hash="somehash"}}
     *  {{pathFor route='items' id=5 query="view=all" hash="somehash"}}
     */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多