Ember.JS中的动态计算属性已弃用?

and*_*ndy 9 ember.js

我正在尝试制作一个余烬应用程序.我有一个计算属性,控制器看起来像这样:

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

现在我正在使用的教程是使用旧版本的Ember.JS.我修复了每个错误,但是这个:

Uncaught Error: assertion failed: Ember.Object.create no longer supports defining computed properties.

有什么替代方法可以做到这一点?

DF_*_*DF_ 10

计算属性仅在create()对象的函数上弃用.如果要创建计算属性,则必须首先extend()是对象,然后是create()它.

例如:

// The Controller

Todos.TodosController = Ember.Controller.extend({

    // ** SNIP ** //

    countCompleted: function()
    {
        return this.get('todos').filterProperty('completed', true).length
    }.property(),
});

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