我试图制作一个垃圾应用程序.我有一个计算属性,控制器如下所示:
// The Controller Todos.Controller = Ember.Controller.create({ // ** SNIP ** // countCompleted: function() { return this.get('todos').filterProperty('completed',true).length }.property(),}); // The View {{Todos.Controller.countCompleted.property}} Items Left
现在我正在关注的教程是使用旧版本的Ember.JS.我已经修复了每个错误,但是这样:
未捕获错误:断言失败:Ember.Object.create不再支持定义计算属性.
这样做的另一种方法是什么?
解决方法
计算的属性仅在对象的create()函数中被弃用.如果要创建一个计算属性,则必须先扩展()对象,然后再创建()它.
例如:
// The Controller Todos.TodosController = Ember.Controller.extend({ // ** SNIP ** // countCompleted: function() { return this.get('todos').filterProperty('completed',}); // Note the lower case 't' here. We've made a new object Todos.todosController = Todos.TodosController.create(); // The View // We reference the created object here (note the lower case 't' in 'todosController') {{Todos.todosController .countCompleted.property}} Items Left
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。