简体   繁体   English

Ember如何从父控制器访问子控制器

[英]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 . 我有一个人员列表,我想显示使用Ember.js编辑的记录 Inside PeopleController, I'm trying to count the attribute isEditing from PersonController with the following code: 在PeopleController中,我正在尝试使用以下代码从PersonController计算属性isEditing

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. 不幸的是,我从editCounter函数得到0。 This attribute ( isEditing ) should tell me how many people are being edited. 此属性( isEditing )应该告诉我正在编辑的人数。 The function editCounter is called inside the html archive that I called index.html: 函数editCounter在我称为index.html的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 ? 所以这是我的问题:如何在PeopleController中正确访问isEditing

In your ArrayController ensure you are setting the itemController: 在您的ArrayController中确保您正在设置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 http://jsbin.com/eyegoz/4/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM