ArrayController's property for each item in the model in ember

I posted this question in stackoverflow but didn’t get any answer. So I’m posting here.

I’ve an Array controller which has the property “isChecked” (boolean property). In my controller I want to get the collection of elements which are “checked” (I mean selected). I’m not sure how to access the controller’s property in the model.

My controller is as follows:

App.ExampleController = Ember.ArrayController.extend({
    isChecked: false,
    totalElements: function()
        return this.model.get('length');
    selectedElements: function()
        var content = this.get('content');
        return content.filterBy('isChecked');
    }.property('isChecked'), });

I linked the “isChecked” property to a checkbox inside each helper as follows…

   {{#each model}}
            {{input type="checkbox" checked=isChecked}}

I will display all the items in the model with a checkbox associated with it. The user can select few items from it. So I want those items.

Now I want to get the list of elements which are “checked”. Either as a computed property or under any action.

Have you looked at the ember getting started guides? I think this is exactly what you want :smile:

Couple things to note:

  • Ember.ArrayController is going away in the future. It’s safer to use Ember.Controller.extend instead

  • The context switching form of {{each}} is deprecated. Use {{#each checkbox in model}} instead.

I actually worked it completely. The difference between the todo app and mine is that it uses store. Whereas in my app I don’t. I directly return the response from the web service to the model.