javascript – if语句导致TpyeError:不能调用未定义的unchain

前端之家收集整理的这篇文章主要介绍了javascript – if语句导致TpyeError:不能调用未定义的unchain前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的车把模板中使用if语句. if语句有效,但是当您尝试更改路由时,它会导致Uncaught TypeError:无法调用未定义的方法’unchain’.

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

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

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

解决方法

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

我建议您只需更新到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

原文链接:https://www.f2er.com/js/157886.html

猜你在找的JavaScript相关文章