【发布时间】:2014-04-10 04:21:21
【问题描述】:
我有一个Posts 集合,其中集合中的每个Post 都有一个userId 属性。在我的帖子详细信息页面上,我想使用 pathFor 帮助程序将用户名与指向其个人资料的链接一起包装起来。如果我只包含{{pathFor 'userProfile'}},它会设置与帖子的_id 的链接,正如人们所期望的那样,但我显然需要链接中的userId。
我已经尝试像这样在模板的帮助器上创建第二个数据上下文,但这也不起作用。
脚本:
Template.postPage.helpers({
user: function () {
return {_id: this.userId};
}
});
模板:
<template name="postPage">
{{#with user}}<a href="{{pathFor 'userProfile'}}">{{/with}}{{author}}</a>
</template>
如何将pathFor 与我的Post 文档中的userId 字段一起使用,而不是我的Post 文档中的_id 字段?
如果这很重要,我正在使用 Iron-router。
【问题讨论】:
标签: meteor iron-router