我正在尝试根据 API 调用的结果动态附加子 riot.js 标记。每当我尝试使用 jquery 的.append()
函数附加这些标签时,DOM 都不会更新。我尝试了这个github线程上描述的以下方法(这对我不起作用):
https://github.com/riot/riot/issues/2279
var myTag = document.createElement('my-tag')
$('#container').append(myTag)
riot.mount(myTag)
这是我正在尝试做的一个简化示例(下面也列出了代码):https ://jsfiddle.net/7m2z7cus/12/
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://rawgit.com/riot/riot/master/riot.min.js"></script>
</head>
<body>
<foo></foo>
<script>
riot.tag('bar', '<h1>hello</h1>', '', '', function(opts) { });
riot.tag('foo', '<div id="bars"></div>', '', '', function(opts) {
var bar = document.createElement('bar');
$('#bars').append(bar);
riot.mount(bar);
});
riot.mount('foo');
</script>
</body>
</html>
我希望#bars
divbar
附加一个标签,在屏幕上显示“Hello”,但它不存在。页面是空白的。我应该如何像上面的示例一样动态附加嵌套标签?