<p id="content"></p>
<script id="test" type="text/html">
<h1>{{title}}</h1>
<ul>
    {{each data as value i}}
        <li>索引 {{i + 1}} :{{value}}</li>
    {{/each}}
</ul>
</script>
<script>
var data = [{
    title: '基本例子1',
    data: ['文艺1', '博客1', '摄影1', '电影1', '民谣1', '旅行1', '吉他1']
},{
    title: '基本例子2',
    data: ['文艺2', '博客2', '摄影2', '电影2', '民谣2', '旅行2', '吉他2']
}];
for (d in data) {
//  alert(JSON.stringify(data[d]))
var html = template('test', data[d]);
}
document.getElementById('content').innerHTML = html;
</script>
这样子遍历为什么只出来1组?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
可能你理解有误
应该是
然后模板部分可以这么写
bug fix
你说的 只出来一组是因为 你一个for in 后,
html 代表的是最后一组数据的html 呢。
请问JS如何操作artTemplate编译过的元素呢?
html要累加 你原来的会覆盖
你这个使用item的时候不加#引用,不会报错的吗?