草庐IT

javascript - Ember.js - "Cannot perform operations on a Metamorph that is not in the DOM"由模板引起

coder 2024-07-16 原文

我一直遇到 Ember.js 抛出错误的问题:

Uncaught Error: Cannot perform operations on a Metamorph that is not in the DOM.

我找到了 these two SO问题,这两个问题都涉及直接操作DOM,而在我的应用程序中并非如此。搜索错误消息还会返回与相同类型的直接 DOM 操作相关的许多 Github 问题。

最佳答案

直到我偶然发现this issue,我才感到茫然。在 Github 上来自 search与错误消息完全无关。

基本上,错误归结为包含在 HTML 注释中的 Handlebars 表达式。

用代码说起来可能比用文字说起来容易,所以这里有一个带有大量解释的 jsFiddle:http://jsfiddle.net/niaconis/JSj7W/1/

{{computedProp}} 表达式在模板中的三个地方使用:正常情况下,在 HTML 注释中,以及在 Handlebars block 注释中。打开网络检查器并单击“重新计算”按钮以查看产生的错误。

您可以从示例的模板中删除 HTML 注释,并看到代码在不存在时运行得很好。

希望这会引导其他蓬勃发展的 Ember 开发人员更容易地采用这种简单的解决方案。

关于javascript - Ember.js - "Cannot perform operations on a Metamorph that is not in the DOM"由模板引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17495659/

有关javascript - Ember.js - "Cannot perform operations on a Metamorph that is not in the DOM"由模板引起的更多相关文章

随机推荐