【发布时间】:2018-07-19 18:04:17
【问题描述】:
我有一个这种格式的数组:
{[
{ title : "", artist : "" },
{ title : "", artist : "" },
{ title : "", artist : "" },
{ title : "", artist : "" }
]}
当我尝试打印数据时,我得到了 n 次完整的模板(Json 数据长度)。我有:
var list = new Array();
list.push({ title : **data**, artist : **data** });
var songsTemplate = $.templates("#topSongsTemplate");
var html = songsTemplate.render(list);
$("#topSongs").html(html);
我只希望我的模板的 for 重复。但是我在我的 div 中一直重复得到完整的模板。我错过了什么?:
<script type="text/x-jsrender" id="topSongsTemplate">
<div class="col-md-6">
<i class="fa fa-trophy"></i> <span data-i18n="search.top_tracks">Top 20 Tracks</span>
<div class="separator hr-line-dashed m-t-xs"></div>
<ol>
{{for ~root }}
<li>{{>title}} - <small>{{>artist}}</small></li>
{{/for}}
</ol>
</div>
</script>
【问题讨论】: