Ember JS,更新不反映在视图中的数组

Nad*_*sin 5 ember.js ember-data

更新Ember JS数组不会反映在视图中.

调节器

App.MyController = Ember.ArrayController.extend({
  results: [],
  init: function(){
    _this = this
    App.MyModel.find({}).then(function(contents) {
      obj1 = contents.objectAt(0)
      obj1.get('data').hasMany.results.forEach(function(item){
          _this.results.push(item)
      });
    })
    //rest of the code
  }
})
Run Code Online (Sandbox Code Playgroud)

模板

{{#each results}}
  // show items of reults.
{{/each}}
Run Code Online (Sandbox Code Playgroud)

这是我从服务器获取数据的代码片段,在加载时,我将其推入结果数组.从服务器加载数据需要一些时间,因此模板映射到空结果数组.理想情况下,结果数组应该更新模板中的内容,但逻辑上不应该更新.

有没有人知道我失踪的地方?或做错了.

提前致谢.

int*_*xel 17

对于绑定工作,您必须使用pushObject而不是push.

App.MyController = Ember.ArrayController.extend({
  results: [],
  init: function(){
    _this = this;
    App.MyModel.find({}).then(function(contents) {
      obj1 = contents.objectAt(0);
      obj1.get('data').hasMany.results.forEach(function(item){
        _this.results.pushObject(item)
      });
    })
    //rest of the code
  }
});
Run Code Online (Sandbox Code Playgroud)

有关ember数组的详细信息,pushObject请参阅此处.

希望能帮助到你.