【问题标题】:How would you use rivets.js with HTML template tags你会如何使用带有 HTML 模板标签的 rivets.js
【发布时间】:2025-12-30 22:20:16
【问题描述】:
【问题讨论】:
标签:
html
rivets.js
html5-template
templatetag
【解决方案1】:
您可以照常复制模板,然后使用铆钉绑定到您的新元素。 demo @ jsfiddle
HTML:
<template id="demo">
<p id="tag">{ demo.info }<p>
</template>
Javascript:
var demo = {
info: "Test string"
}
// Copy template data to visible DOM
var el = document.getElementById("demo");
var clone = document.importNode(el.content, true);
document.body.appendChild(clone);
// Bind using Rivets as normal
var tag = document.getElementById("tag");
rivets.bind(tag, { demo: demo });