javascript - 全局助手正在覆盖 meteor handlebars 模板中的本地上下文

标签 javascript coffeescript meteor handlebars.js

更新:所选答案中记录的错误已由 meteor 开发人员修复

在我的 meteor 应用程序中,我有一些制作全局助手的 coffescript:

Handlebars.registerHelper "title",->
    Session.get("title")

和一个模板:

{{#each edited}}
    <li><a class="left-nav" href="{{entryLink this}}">{{this.title}}</a></li>
{{/each}}

this.title 被全局助手覆盖,而不是使用 this.title 上下文。 (我知道,因为如果我删除全局助手,它会很好用)

如果我添加以下内容:

Handlebars.registerHelper "debug", ->
    console.log this
    console.log this.title

像这样的模板:

{{#each edited}}
    <li><a class="left-nav" href="{{entryLink this}}">{{this.title}}{{debug}}</a></li>
{{/each}}

this.title 正确地打印到控制台,但没有插入到模板中

任何想法为什么会发生这种情况或如何使“this.title”来自本地上下文

最佳答案

https://github.com/meteor/meteor/wiki/Handlebars#expressions-with-dots 以来,我觉得这是个错误说:

Paths starting with this always refer to properties of the current data context and not to helpers.

我为此提交了一个问题:https://github.com/meteor/meteor/issues/1143

关于javascript - 全局助手正在覆盖 meteor handlebars 模板中的本地上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16880462/

相关文章:

javascript - jQuery .each() 和 ajax 获取大小

javascript - jQuery预选下拉菜单不进入Change()函数

javascript - MongoDB 无法将 $addToSet 应用于 Meteor JS 中的非数组

meteor - AccountsTemplates 未定义

javascript - "Uncaught ReferenceError: Template is not defined"(路由器、Meteor、Mongo 相同)

javascript - 如何永久更改对象的样式?

javascript - 跨机器安排和/或同步 HTML5 视频播放

javascript - 在 Rails View 中发出 Javascript Loop 请求

javascript - 如何在 javascript (meteor.js) 中操作返回的 mongo 集合/游标?

javascript - 将动态生成的 div id 从 Rails 传递到 javascript/coffeescript