【问题标题】:pathFor parameters no longer working after Blaze upgradeBlaze 升级后 pathFor 参数不再起作用
【发布时间】:2014-05-15 20:17:21
【问题描述】:

我将流星 0.7 更新到 0.8,将 Iron router 0.6.2 更新到 0.7.0,并添加了 blaze-layout 0.2.2。

以前我有 pathFor 使用两个参数。精简到看起来像这样的基本部分:

{{#each users}}                                                                                                                                                                          
   <a href="{{pathFor 'template' _id=this._id fooParam=foo}}">link text</a>
{{/each}}

更新后的 pathFor 只返回模板的 url,参数没有做任何事情。我也可以显示变量,一切都显示正确:

{{#each users}}
   {{this._id}} {{!displayed correctly in browser}}  
   {{foo}}      {{!displayed correctly in browser}}                                                                                                                            
   <a href="{{pathFor 'template' _id=this._id foo_param=foo}}">link text</a>
{{/each}}

如果我只是尝试使用设置了 _id 的数据上下文,结果不会改变:

{{#each users}}                                                                                                                            
   <a href="{{pathFor 'template'}}">link text</a>
{{/each}}

任何想法将不胜感激!

【问题讨论】:

    标签: meteor iron-router meteor-blaze


    【解决方案1】:

    来自History.mdiron-router 回购:

    {{pathFor}} 和 {{urlFor}} 仍然适用于一些 api 更改:

    • {{pathFor 'routeName' params=this query="key=value&key2=value2" hash="somehash" anotherparam="anothervalue"}}
    • 同样适用于 {{urlFor}}

    来自code(第 41-47 行)中的 cmets:

     /**
     * 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"}}
     */
    

    换句话说,您的 pathFor 助手需要如下所示:

    <a href="{{pathFor 'template' _id=this._id query="foo_param=foo"}}">link text</a>
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      fletch 是正确的,因为我昨天修复了同样的事情。请参阅https://github.com/EventedMind/iron-router/issues/580#issuecomment-39526280

      对于每个 pathFor,我在浏览器控制台中收到以下错误:

      Exception in Meteor UI: TypeError: Cannot read property 'params' of undefined
      at Object.processPathArgs (http://localhost:3000/packages/iron-router.js?a4167ac4d12a73891d8a9b8c57419a347da0ee12:2200:22)
      at Object._.extend.pathFor (http://localhost:3000/packages/iron-router.js?a4167ac4d12a73891d8a9b8c57419a347da0ee12:2227:34)
      at http://localhost:3000/packages/ui.js?b523ef986d3d39671bcb40319d0df8982acacfe8:2838:23
      at Spacebars.call (http://localhost:3000/packages/spacebars.js?5d478ab1c940b6f5a88f78b8adc81a47f022da77:173:18)
      at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?5d478ab1c940b6f5a88f78b8adc81a47f022da77:110:25)
      at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?5d478ab1c940b6f5a88f78b8adc81a47f022da77:114:39)
      at HTML.A.href (http://localhost:3000/client/views/prayers/template.prayer_item.js?e15ce9378850d2ce553c8c60647642a543534557:58:30)
      at http://localhost:3000/packages/htmljs.js?697b0dd0fbdd1f8984dffa3225121a9b7d0b8609:254:14
      at callWithNoYieldsAllowed (http://localhost:3000/packages/deps.js?7afb832ce6e6c89421fa70dc066201f16f9b9105:74:5)
      at _.extend._compute (http://localhost:3000/packages/deps.js?7afb832ce6e6c89421fa70dc066201f16f9b9105:212:7) 
      

      我只是将各种 {{pathFor 'items' this}} 更改为 {{pathFor 'items' params=this}}

      【讨论】:

      猜你喜欢
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 2017-07-06
      • 1970-01-01
      • 2023-03-14
      • 2017-01-28
      • 1970-01-01
      相关资源
      最近更新 更多