我在我的 Handlebars 模板中使用了 if 语句。 if 语句有效,但是当您尝试更改路由时,它会导致 Uncaught TypeError: Cannot call method 'unchain' of undefined。
我在以下 jsbin 中重新创建了错误
演示:http://emberjs.jsbin.com/UnUVorUn/9
代码:http://emberjs.jsbin.com/UnUVorUn/9/edit
最佳答案
您的问题发生是因为您的 IsLink
以大写字母开头,在 Handlebars 模板中使用时有一个 bug,已在 1.3.0 中修复。但是如果你更新你的 ember 版本,你会遇到一个新问题,因为 ember 认为以大写字母开头的属性是一个全局路径,所以它会查找 sectionController.IsLink
而不是 window.IsLink = 'teste'
。
我建议您只更新到 isLink
以避免这些问题:
App.SectionController = Ember.Controller.extend({
isLink :Ember.computed.equal('model.type', 'link')
});
模板
<ul>
{{#link-to 'index'}} index{{/link-to}}
{{#link-to 'test'}} test{{/link-to}}
{{#each model itemController="section"}}
{{#if isLink}}
<li>{{model.color}}</li>
{{/if}}
{{/each}}
</ul>
http://emberjs.jsbin.com/UnUVorUn/12/edit