0

我正在使用Ember RC6.1Ember Model。当我将模型类的adapter属性设置为 Ember 模型类的实例RESTAdpater并执行 afindAll时,将为添加到生成的 Ember 数组的每个对象引发一个断言。堆栈跟踪显示对象被压入数组,插入,然后替换。我不确定为什么会发生后者(替换)。这可能是隐式排序的结果。

对于每次推送,都会抛出一个断言,声明(继承自)content的实例的属性应在修改之前设置。RecordArrayArrayProxy

Assertion failed: The content property of Ember.RecordArray should be set before modifying it

结果数组表现正常,但我想知道这是 Ember 模型还是 Ember 本身的错误。我假设我的代码不对这个错误负责,因为除了根据 Ember 模型的文档从 API 获取数据之外,我没有做任何不寻常的事情。

我在下面添加了堆栈跟踪。

(anonymous function) application.js:6108
Ember.assert application.js:5799
Ember.ArrayProxy.Ember.Object.extend._replace application.js:17977
Ember.ArrayProxy.Ember.Object.extend._insertAt application.js:17992
Ember.ArrayProxy.Ember.Object.extend.pushObject application.js:18036
superWrapper application.js:6826
Ember.Model.reopenClass.addToRecordArrays application.js:5251
(anonymous function) application.js:5242
sendEvent application.js:7843
Ember.Evented.Ember.Mixin.create.trigger application.js:16867
Ember.Model.Ember.Object.extend.load application.js:4792
Ember.Model.reopenClass.findFromCacheOrLoad application.js:5280
(anonymous function) application.js:4453
Ember.RecordArray.Ember.ArrayProxy.extend.materializeData application.js:4452
Ember.RecordArray.Ember.ArrayProxy.extend.load application.js:4435
Ember.RESTAdapter.Ember.Adapter.extend.didFindAll application.js:5585
(anonymous function) application.js:5576
invokeCallback application.js:12843
(anonymous function) application.js:12886
EventTarget.trigger application.js:12674
(anonymous function) application.js:12941
DeferredActionQueues.flush application.js:10648
Backburner.end application.js:10338
Backburner.run application.js:10377
Ember.run application.js:10859
settings.success application.js:5697
fire application.js:38117
self.fireWith application.js:38228
done application.js:45154
callback

更新:调用pushObject由 Ember 模型执行。我添加了 的实现addToRecordArrays,该方法将记录添加到 的实例中RecordArray

addToRecordArrays: function(record) {
  if (this._findAllRecordArray) {
    this._findAllRecordArray.pushObject(record);
  }
  if (this.recordArrays) {
    this.recordArrays.forEach(function(recordArray) {
      recordArray.pushObject(record);
    });
  }
}
4

1 回答 1

1

我已经恢复了引入这个问题的提交。

于 2013-08-08T19:58:31.660 回答