if语句导致TpyeError:Cannont调用未定义的unchain

Bil*_*nks 7 javascript ember.js

即时通讯在我的车把模板中使用if语句.if语句有效,但是当你尝试更改路由时,它会导致Uncaught TypeError:无法调用未定义的方法'unchain'.

我在以下jsbin中重新创建了错误

演示:http://emberjs.jsbin.com/UnUVorUn/9

代码:http://emberjs.jsbin.com/UnUVorUn/9/edit

Mar*_*ior 10

您的问题发生是因为您IsLink以大写字母开头,在车把模板中使用时存在错误,已在1.3.0中修复.但是如果你更新你的ember版本,你会遇到一个新问题,因为ember认为一个以大写字母为全局路径的属性,所以sectionController.IsLink不会查找window.IsLink = 'teste'.

我建议您只需更新isLink以避免这些问题:

App.SectionController = Ember.Controller.extend({
  isLink :Ember.computed.equal('model.type', 'link')
});
Run Code Online (Sandbox Code Playgroud)

模板

<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>
Run Code Online (Sandbox Code Playgroud)

http://emberjs.jsbin.com/UnUVorUn/12/edit