Javascript 使用聚合物模板化器标记模板
如果需要,我想添加模板的内容,如果不需要,则将其删除。我的代码是基于polymer的dom if实现的 这是添加模板内容的代码Javascript 使用聚合物模板化器标记模板,javascript,polymer-1.0,Javascript,Polymer 1.0,如果需要,我想添加模板的内容,如果不需要,则将其删除。我的代码是基于polymer的dom if实现的 这是添加模板内容的代码 if (!this.ctor) { this.templatize(this); } if (parentNode) { const parent = Polymer.dom(parentNode); if (!this._instance) { this._instance = this.stamp(); const targetNod
if (!this.ctor) {
this.templatize(this);
}
if (parentNode) {
const parent = Polymer.dom(parentNode);
if (!this._instance) {
this._instance = this.stamp();
const targetNode = parent.firstElementChild;
const newNode = this._instance.root;
parent.insertBefore(newNode, targetNode);
} else {
const children = this._instance._children;
if (children && children.length) {
const lastChild = Polymer.dom(this).previousSibling;
if (lastChild !== children[children.length - 1]) {
for (let i = 0, node; i < children.length && (node = children[i]); i++) {
parent.insertBefore(node, this);
}
}
}
}
}
因为节点只包含#文档片段,而不包含dom repeat插入的内容
我试图达到正确的内容,但我失败了。是否有可能插入正确的内容,即使它包含dom repeat、dom if等
多谢各位
if (this._instance) {
const children = this._instance._children;
if (children && children.length) {
const parent = Polymer.dom(Polymer.dom(children[0]).parentNode);
for (let i = 0, n; i < children.length && (n = children[i]); i++) {
parent.removeChild(n);
}
}
if(this.restamp) {
this._instance = null;
}
}
parent.insertBefore(node, this);