1

我将流星 0.7 更新为 0.8,将铁路由器 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}}

任何想法将不胜感激!

4

2 回答 2

2

来自回购的History.md :iron-router

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

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

根据代码中的注释(第 41-47 行):

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

希望有帮助。

于 2014-04-04T04:11:27.503 回答
1

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

于 2014-04-04T09:01:07.003 回答