meteor - Handlebars + meteor +铁路由器

标签 meteor handlebars.js iron-router

我正在为我的 meteor 项目使用铁路由器,一切顺利,但我遇到了一些奇怪的行为。

我为看起来像这样的项目列表设置了一个循环。

{{#each list_items}}
  <div>{{user.username}}
    <a href="{{link}}">Click here!</a>
  </div>
{{/each}}

我的用户的 JSON 对象如下所示:
{
  user: {
      username: jdoe
    },
  images: {
    low-res-url: http://example.com
  },
  link: http://example.com/profile
}

现在 {{user.username}} 按预期显示,但是当我尝试将 {{link}} 放在 href 中时,我收到了来自 Iron-router 的错误消息
"You called Router.path for a route named undefined but that that route doesn't seem to exist. Are you sure you created it?" 

任何帮助或建议将不胜感激。

最佳答案

在引擎盖下 Iron-Router 注册handelbars helper:

Handlebars.registerHelper('link', function (options) {                          
  ...
}); 

只需更改字段 link到不同的名称,如 my_link .

关于meteor - Handlebars + meteor +铁路由器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19877813/

相关文章:

javascript - 如何从不包含express.static的文件夹中渲染模板?

handlebars.js - 如何删除由 Handlebars 生成的换行符?

Meteor Router.go() 不重定向,但它在 Chrome 控制台中工作

mongodb - 将本地 mongo 集合部署到 meteor.com 服务器

meteor - 如何使用 Docker 将 Meteor 和 Phusion Docker 部署到 Digital Ocean?

haml - meteor 与haml

javascript - 如何合并不同集合的游标并按日期排序

javascript - 在 emberjs 中访问 #each 中的索引

Meteor Iron Router 使用模板助手中的参数从路由中获取当前路径

javascript - 使用iron-router版本1.0.0-pre2下载文件链接