fun*_*eah 5 javascript coffeescript handlebars.js meteor
更新:所选答案中记录的错误已由流星开发者修复
在我的流星应用程序中,我有一些coffescript作为全球帮手:
Handlebars.registerHelper "title",->
Session.get("title")
Run Code Online (Sandbox Code Playgroud)
和一块模板:
{{#each edited}}
<li><a class="left-nav" href="{{entryLink this}}">{{this.title}}</a></li>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
this.title被全局帮助器覆盖,而不是使用this.title上下文.(我知道,因为如果我删除全局帮助程序,它可以很好地工作)
如果我添加以下内容:
Handlebars.registerHelper "debug", ->
console.log this
console.log this.title
Run Code Online (Sandbox Code Playgroud)
到这样的模板:
{{#each edited}}
<li><a class="left-nav" href="{{entryLink this}}">{{this.title}}{{debug}}</a></li>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
this.title正确打印到控制台,但未插入模板
知道为什么会这样或者如何使"this.title"来自本地环境
对我来说看起来像一个错误,因为https://github.com/meteor/meteor/wiki/Handlebars#expressions-with-dots说:
以 开头的路径
this始终引用当前数据上下文的属性,而不是帮助程序。
我为此提交了一个问题:https ://github.com/meteor/meteor/issues/1143