![](/img/trans.png)
[英]Ember.js - Cannot perform operations on a Metamorph that is not in the DOM
[英]Ember.js - “Cannot perform operations on a Metamorph that is not in the DOM” caused by template
直到我在Github上發現這個與錯誤消息完全無關的搜索時,我才感到茫然。
基本上,錯誤歸結為HTML注釋中包含的Handlebars表達式。
在代碼中比在單詞中說起來可能更容易,所以這里有一個jsFiddle有很多解釋: http : //jsfiddle.net/niaconis/JSj7W/1/
{{computedProp}}
表達式在模板中使用了三個位置:正常情況下,在HTML注釋中以及Handlebars塊注釋中。 打開Web檢查器並單擊“重新計算”按鈕以查看生成的錯誤。
您可以從示例的模板中刪除HTML注釋,並看到代碼在不存在時運行正常。
希望這將引導其他開花的Ember開發人員更容易地使用這樣一個簡單的解決方案。
問題很簡單,但追蹤實際原因很難。 對於我們使用metamorph跟蹤的項目,它包含一個id為metamorph-##-start
的腳本元素metamorph-##-start
和id metamorph-##-end
。 在正常情況下,除非不再需要,否則Ember不應將它們移除。 有幾個原因可以解決這個問題:
另一個原因是當我們使用把手數據時HTML標簽中的屬性,例如:
<div data-id="{{ model.id }}" ...
使用binding element attributes
而不是普通方法,例如:
<div {{ bind-attr data-id=model.id }} ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.