我有一组模型,我正在循环使用Handlebars模板化。我想为每个输出模型添加索引号,但我不确定这是如何完成的,我已经尝试@index
和@key
没有成功,有人可以推荐我需要做的事情?
收集代码段
dataStore.searchResultsCollection = new PlaylistCollection([
{
'id': 'h5EofwRzit0',
'artist': 'Daft Punk',
'song_name': 'Get Lucky (Official Audio)',
'video_id': 'h5EofwRzit0',
'video_author': 'DaftPunkVEVO',
'video_description': 'Random Access Memories, in stores now: iTunes: http://smarturl.it/RAMiTunes Amazon (CD/LP): http://smarturl.it/ram-amazon Direct (CD/LP): http://www.myplaydi...',
'video_img': 'http://i.ytimg.com/vi/5NV6Rdv1a3I/default.jpg',
'likes': '874413',
'dislikes': '28789'
} ...
句柄摘录
<p class="item-delete js-delete-video" data-id="{{id}}" id="{{id}}">delete</p>
<p class="item-title js-play-video" data-id="{{id}}" id="{{id}}" data-index="{{@index}}" title="{{artist}} - {{song_name}}">{{artist}} - {{song_name}}</p>
输出模板如下所示:
<li><p class="item-delete js-delete-video" data-id="h5EofwRzit0" id="h5EofwRzit0">delete</p>
<p class="item-title js-play-video" data-id="h5EofwRzit0" data-song="Get Lucky (Official Audio)" id="h5EofwRzit0" data-index="" title="Daft Punk - Get Lucky (Official Audio)">Daft Punk - Get Lucky (Official Audio)</p>
</li>