Danilo Caetano
Danilo Caetano

Reputation: 239

Ember how to access a child controller from a parent controller

I have a list of people and I'd like to show how many records are being edited using Ember.js. Inside PeopleController, I'm trying to count the attribute isEditing from PersonController with the following code:

Schedule.PeopleController = Ember.ArrayController.extend({ 
    editCounter: function () {
        return this.filterProperty('isEditing', true).get('length');
    }.property('@each.isEditing')
});
Schedule.PersonController = Ember.ObjectController.extend({
        isEditing: false
});

Unfortunately, I'm getting 0 as a result from editCounter function. This attribute (isEditing) should tell me how many people are being edited. The function editCounter is called inside the html archive that I called index.html:

...
            {{outlet}}
            <div id="count_edits">
                <span id="total_edits">
                    <strong>Editing: </strong> {{editCounter}}
                </span>
            </div>
...

So here is my question: How would I access correctly isEditing inside PeopleController?

Upvotes: 4

Views: 1935

Answers (1)

RyanHirsch
RyanHirsch

Reputation: 1847

In your ArrayController ensure you are setting the itemController:

Schedule.PeopleController = Ember.ArrayController.extend({ 
    itemController: 'Person',
    editCounter: function () {
        return this.filterProperty('isEditing', true).get('length');
    }.property('@each.isEditing')
});

See http://jsbin.com/eyegoz/4/edit

Upvotes: 4

Related Questions