Ember how to access the child controller from the parent controller

I have a list of people and I would like to show how many posts are edited using Ember.js . Inside the PeopleController, I am trying to calculate the isEditing attribute 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 get 0 as a result of the editCounter function. This attribute ( isEditing ) should tell me how many people are being edited. The editCounter function is called inside the html archive, which 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 can I get isEditing correctly inside PeopleController ?

+4
source share
1 answer

In your ArrayController, make sure you set 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

+4
source

Source: https://habr.com/ru/post/1493522/


All Articles