编辑:精简版JSBin link
我遇到了一个问题,当我创建新记录时,我收到错误说"未捕获的异常:您无法在已插入的DOM中插入元素&# 34。
摘自index.html
:
<ul id="flowList">
{{#each}}
{{#if isTemplate}}
{{view App.FlowView}}
{{/if}}
{{/each}}
</ul>
<ul id='levelsList'>
<ul id='level1'>
{{#each}}
{{#if isLevelOne}}
{{view App.FlowView}}
{{/if}}
{{/each}}
</ul>
</ul>
我使用isLevelOne false预加载了一个Flow对象,并且isTemplate为true。它有一个按钮,它创建一个新流,使得计算属性isLevelOne为true,属性isTemplate为false - 我在Ember Inspector中对此进行了验证。但是,当发生这种情况时,我会得到一个uncaught exception: You can't insert an element into the DOM that has already been inserted
,尽管该页面似乎正常。当我尝试刷新页面(将新记录保存到商店中)时,它无法呈现页面并抛出Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.
这些错误对我来说都没有任何意义 - 任何帮助都会受到赞赏。< / p>
编辑:下面包含的FlowView模板
<script type="text/x-handlebars" data-template-name='flow-view'>
<li {{bind-attr id=title class=":flow isTemplate"}}>
{{#if isTemplate}}
<button {{action "insertIntoSandbox" this}}>+</button>
{{/if}}
<label>{{title}}</label>
{{#unless isDefault}}
<button {{action "removeFlow" this}} {{bind-attr class="isTemplate"}}>−</button>
{{/unless}}
</li>
</script>
编辑:下面添加了PortkeyController
App.PortkeyController = Ember.ArrayController.extend({
actions: {
/**
* @elem is the flow associated with the button -- can use this to duplicate
*/
insertIntoSandbox: function(elem) {
var _store = this.store;
var newFlowJSON = elem.toJSON();
console.log(newFlowJSON); // isDefault=true, isTemplate=true, params=[] from element
delete newFlowJSON.id; // might be unnecessary?
newFlowJSON.title = 'gg';
newFlowJSON.level = 1;
newFlowJSON.isLevelOne = false;
var newFlow = _store.createRecord('flow', newFlowJSON);
newFlow.save();
},
});
答案 0 :(得分:1)
我怀疑,在尝试删除/添加元素时,Ember通常会使用无效的HTML。 (我不确定它是Ember,还是浏览器通过为您注入结束标记来帮助,然后Ember不删除浏览器帮助标记)
FlowView缺少结束LI
标记。