.js 文件;
var dataModel = Backbone.Model.extend({
defaults : {
dataID : 'unknown',
text : 'unknown'
}
});
var LinkCollection = Backbone.Collection.extend({
model : dataModel
});
假设集合大小为 8。我想一次显示 3 个。由于脚本的结构,我需要将集合项划分为单独的 div。
.html 文件;
<div class="item">
<div class="carousel-subItem"> <-- Collection item #1
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
<div class="carousel-subItem"> <-- Collection item #2
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
<div class="carousel-subItem"> <-- Collection item #3
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
</div>
<div class="item">
<div class="carousel-subItem"> <-- Collection item #4
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
<div class="carousel-subItem"> <-- Collection item #5
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
<div class="carousel-subItem"> <-- Collection item #6
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
</div>
<div class="item">
<div class="carousel-subItem"> <-- Collection item #7
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
<div class="carousel-subItem"> <-- Collection item #8
<span>{{dataID}}</span> <br /> <span>{{text}}</span>
</div>
</div>
我很难动态地创建这个 html 结构。(因为集合大小可以变化......结构应该是完全动态的等;
{{#each dataModel}}
// code goes here, to create the above structure..
{{/each}}