HandlebarsJS - 如何分割数据

时间:2014-03-04 16:26:50

标签: backbone.js handlebars.js

我有这个Backbone App,我有一个API,可以从MySQL数据库中获取有关Bands Album及其相关曲目的信息。当我执行经典{{#each this}} - 事物时,我会将所有数据列在一个大的<ol>中 - 并且您无法查看曲目所属的相册。我想要实现的是这样的结构:

 <album>
    <tracks>

 <album>
    <tracks>

 ...etc

现在,我的代码看起来像这样:

<div>
{{#each this}}
<div class="pc33">        
    <img src="{{cover_image}}" />
</div>
<section>
    <h2>{{album_title}}</h2>
</section>
<section class="tl pc66 floatright">
    <div>
        <ol>
            {{#each this}}
            <li>{{track_title}}<span>{{track_duration}}</span></li>
            {{/each}}
        </ol>
    </div>
</section>
{{/each}}
</div>

但这不起作用 - 每首曲目都会获得专辑封面并以1.曲目标题开始...

我的控制台吐出JSON

0: {pro_id:507, album_title:I Care 4 U, track_title:…}
1: {pro_id:507, album_title:I Care 4 U, track_title:…}
2: {pro_id:507, album_title:I Care 4 U, track_title:…}
3: {pro_id:507, album_title:I Care 4 U, track_title:…}
4: {pro_id:508, album_title:Miss You, album_genre:R & B, cover_image:…}
5: {pro_id:509, album_title:One In A Million, track_title:…}
6: {pro_id:509, album_title:One In A Million, track_title:…}
7: {pro_id:509, album_title:One In A Million, track_title:…}
8: {pro_id:509, album_title:One In A Million, track_title:…}
9: {pro_id:509, album_title:One In A Million, track_title:…}
10: {pro_id:509, album_title:One In A Million, track_title:…}
11: {pro_id:510, album_title:Aaliyah, track_title:…}
12: {pro_id:510, album_title:Aaliyah, track_title:…}
13: {pro_id:510, album_title:Aaliyah, track_title:…}
14: {pro_id:510, album_title:Aaliyah, track_title:…}
15: {pro_id:510, album_title:Aaliyah, track_title:…}
16: {pro_id:510, album_title:Aaliyah, track_title:…}

所以,我想要有如上所述的结构。我怎么能这样做?

提前致谢

0 个答案:

没有答案