我试图制作一个垃圾应用程序.我有一个计算属性,控制器如下所示:
// 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