Dynamic computed properties in Ember.JS deprecated?

后端 未结 2 1754
失恋的感觉
失恋的感觉 2021-02-08 19:37

I am trying to make an ember application. I have a computed property and the controller looks like this:

// The Controller

Todos.Controller = Ember.Controller.c         


        
相关标签:
2条回答
  • 2021-02-08 19:59

    It also seems to work ok if you do a reopen:

    Todos.todosController = Ember.Controller.create({
        // ** SNIP ** //
    });
    
    Todos.todosController.reopen({
        countCompleted: function() {
            return this.get('todos').filterProperty('completed', true).length
        }.property(),
    });
    
    0 讨论(0)
  • 2021-02-08 20:09

    The computed property is only deprecated on the create() function of an object. If you wish to create a computed property, then you must first extend() the object, and then create() it.

    For example:

    // 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
    
    0 讨论(0)
提交回复
热议问题