我对riot.js非常陌生,也许我要求的是一件显而易见的事情。
如果我静态地添加标记,然后挂载它--一切都很完美。但是,如果我尝试使用JavaScript动态添加标记,我什么也看不到。我想我必须以某种方式挂载新创建的元素,但我不知道如何做到这一点。
<script src="https://cdnjs.cloudflare.com/ajax/libs/riot/2.6.7/riot+compiler.min.js"></script>
<body>
<h1>
testing riot.js
</h1>
<ol id="list">
<li>
<example></example>
</li>
<li>
<example></example>
</li>
</ol>
<button onclick="addTag()">Add tag</button>
<script type="riot/tag">
<example>
<p>Welcome to Riot.js</p>
</example>
</script>
<script>
riot.mount('example');
function addTag(){
var list = document.getElementById("list");
var li = document.createElement('li');
list.appendChild(li);
var tag = document.createElement('example');
li.appendChild(tag)
}
</script>
</body>
发布于 2016-11-17 09:05:51
必须在将节点添加到DOM之后调用riot.mount:
function addTag(){
var list = document.getElementById("list");
var li = document.createElement('li');
list.appendChild(li);
var tag = document.createElement('example');
li.appendChild(tag)
riot.mount(tag, 'example');
}https://stackoverflow.com/questions/40649073
复制相似问题