Ember.js:视图绑定无法正常工作

时间:2014-07-16 01:25:27

标签: javascript ember.js

我有以下情况:

controller.hbs:

<div> <h2>Filters</h2>
{{view App.FilterView title="Company" activeMembersBinding="activeMembers"}}
</div>

filter.hbs

 <ul>
 {{#each activeMembers}}
    <li>{{this}}</li>
 {{/each}}
 </ul>

controller.js

App.CompanyController = Ember.Controller.extend({
    activeMembers: Embers.A(['a', 'b'])
});

到目前为止,一切正常,但当我尝试在控制器阵列中添加新成员时,视图中没有任何更新:

controller.js

App.CompanyController = Ember.Controller.extend({
    activeMembers: Embers.A(['a', 'b']),

    actions:{
        addMember: function(member){
             var members = this.get('activeMembers');
             members.push(member);
             this.set('activeMembers', member);
        }
    }
});

1 个答案:

答案 0 :(得分:1)

您需要使用pushObject代替push,它本质上是Ember可以观察并对数组更改做出反应的setter。

members.pushObject(member);