【问题标题】:cannot perform operations on a Metamorph that is not in the DOM无法对不在 DOM 中的 Metamorph 执行操作
【发布时间】:2014-04-14 09:27:33
【问题描述】:

所以我使用的是 Ember 1.5.1 和 Ember-data 1.0.0 beta7

我有以下路线

App.Router.map -> @resource "items" @resource 'item', path: '/items/:id

从服务器获取项目。如果我从那条路线开始,这两条路线可以正常工作;当我从一个项目页面 (/items/1) 开始时,会发生奇怪的事情,然后我尝试通过一个链接导航到 /items/,该链接由 ItemController 中的 this.transitionToRoute("items") 函数处理。我收到以下错误:

尝试过渡到项目 ember.js?body=1:3524

过渡 #2:items:调用 beforeModel 钩子 ember.js?body=1:3524

过渡 #2:items:调用反序列化钩子 ember.js?body=1:3524

Error while loading route: Error: Cannot perform operations on a Metamorph that is not in the DOM.
at Metamorph.checkRemoved (http://localhost:3000/assets/ember.js?body=1:27009:15)
at Metamorph.html (http://localhost:3000/assets/ember.js?body=1:26979:12)
at Object.DOMManager.empty (http://localhost:3000/assets/ember.js?body=1:27974:16)
at Object.Ember.merge.empty (http://localhost:3000/assets/ember.js?body=1:25139:21)
at Ember.CollectionView.Ember.ContainerView.extend.arrayWillChange (http://localhost:3000/assets/ember.js?body=1:25962:25)
at Object.sendEvent (http://localhost:3000/assets/ember.js?body=1:2600:14)
at Ember.Array.Ember.Mixin.create.arrayContentWillChange (http://localhost:3000/assets/ember.js?body=1:15317:11)
at superFunction [as _super] (http://localhost:3000/assets/ember.js?body=1:7726:16)
at RecordArray.extend.arrayContentWillChange (http://localhost:3000/assets/ember-data.js?body=1:7624:28)
at superWrapper [as arrayContentWillChange] (http://localhost:3000/assets/ember.js?body=1:1295:16) 

过渡 #2:项目:过渡已中止

但是,我再次点击链接,转换成功。然后,无论我如何在两条路线之间导航,一切正常。

我最初的猜测是,当我尝试转换时,并非所有记录都已加载,但即使我从 /items/ 开始并转到 /items/1 然后尝试返回 /items/,我仍然得到同样的错误。

【问题讨论】:

    标签: javascript jquery ember.js ember-data url-routing


    【解决方案1】:

    试试这个,在你的操作中添加以下代码

    Ember.run.scheduleOnce('afterRender', this, function(){
        this.transitionToRoute("items");
    });
    

    更新:

    好的,刚刚检查了您的堆栈跟踪。问题不是因为transitionTORoute。由于这是变形问题,因此很难直接调试。这实际上可能是由错误的车把表达式引起的。

    • 正如this link 中指出的,一个简单的问题可能是使用 HTML 注释块。

      {{!此评论不会出现在输出中 }}

    • 手动操作 DOM。如果您手动删除脚本标签,那么它们将找不到。

    • HTML 格式错误。假设您留下了一个打开的 div,那么 metamorph-##-end 标记将嵌套在与开始标记不同的级别。

    我从其他问题中提取了很多我认为可能对你有帮助的观点

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      • 2013-10-16
      • 2017-06-23
      • 2021-11-24
      • 2021-10-31
      • 1970-01-01
      相关资源
      最近更新 更多