gpt4 book ai didi

Polymer 1.0 - injectBoundHTML() 替代方案

转载 作者:行者123 更新时间:2023-12-04 08:06:46 25 4
gpt4 key购买 nike

与injectBoundHTML() 等效的Polymer 1.0 是什么?

(即将 HTML 字符串附加到 Polymer 元素内的节点并解析数据绑定(bind))

一个 JSbin 示例 - http://jsbin.com/jufase/edit?html,output

编辑:还没有足够的信誉来接受我自己的答案,但它应该在下面的某个地方。 TL;DR - 使用“dom-bind”模板

最佳答案

尽管正如 techknowledgey 指出的那样,它还没有得到很好的支持。以下似乎可以解决问题。

function injectBoundHTML(html, element) {
var template = document.createElement('template', 'dom-bind');
var doc = template.content.ownerDocument;
var div = doc.createElement('div');
div.innerHTML = html;
template.content.appendChild(div);
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(Polymer.Base.instanceTemplate(template));
}

如果您的 HTML 已经被解析,那么使用类似“doc.importNode(sourceNode, true);”的东西而不是获取/设置innerHTML。

关于Polymer 1.0 - injectBoundHTML() 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30836412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com