我有一个管理客户列表的控制器。每个客户端都是DS.Model。当我将控制器的内容设置为App.Client.find()的结果时,代码抛出以下异常,即RecordArray。如果我将控制器的内容设置为空数组[]或者当我使用Ember.Object而不是DS.Model作为客户端对象时,我也不会例外
Uncaught Error: Cannot perform operations on a Metamorph that is not in the DOM.
APP.ClientsController = Ember.ArrayController.extend({});
APP.Client = DS.Model.extend({
number:DS.attr('number'),
firstname:DS.attr('string')})
APP.ClientsRoute = Ember.Route.extend({
setupControllers: function(controller) {
controller.set('clients',APP.Client.find());
});
APP.store = DS.Store.create({
revision: 11,
adapter: 'DS.FixtureAdapter'
});
任何想法,我尝试调试源代码,当Ember检测到对控制器内容的更改并触发arrayWillChange事件时,代码失败
arrayWillChange: function(content, start, removedCount) {
// If the contents were empty before and this template collection has an
// empty view remove it now.
var emptyView = get(this, 'emptyView');
if (emptyView && emptyView instanceof Ember.View) {
emptyView.removeFromParent();
}
// Loop through child views that correspond with the removed items.
// Note that we loop from the end of the array to the beginning because
// we are mutating it as we go.
var childViews = get(this, 'childViews'), childView, idx, len;
len = get(childViews, 'length');
var removingAll = removedCount === len;
if (removingAll) {
this.currentState.empty(this);
}
for (idx = start + removedCount - 1; idx >= start; idx--) {
childView = childViews[idx];
if (removingAll) { childView.removedFromDOM = true; }
childView.destroy();
}
},
答案 0 :(得分:1)
原来是干扰外部脚本(Datatable Jquery Plugin)试图修改相同的dom结构ember的控制。