1

我有一个管理客户列表的控制器。每个客户端都是一个 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();
}

},

4

1 回答 1

1

原来是干扰外部脚本(DatatTable Jquery 插件)试图修改相同的 dom 结构 ember 的控制。

于 2013-01-08T16:22:38.730 回答