【发布时间】:2016-06-09 01:54:27
【问题描述】:
我仍在学习 Backbone.js,我不确定一次渲染一个 model 与渲染 collection 之间的优缺点是什么。
我见过他们一次渲染一个model 的例子。例如:
//in parent view
var view = new SectionView({model: section});
this.$("#section-list").append(view.render().el);
//in child view, render()
this.$el.html(this.template(this.model.toJSON()));
使用如下模板:
<script type="text/template" id="section-template">
<section class="view" id=section-<%- id %>>
<label><%- height %></label>
<label><%- color %></label>
<label><%- id %></label>
<button class="destroy">Delete</button>
</section>
</script>
但是,我也看到了渲染整个 collection 的示例,例如 post。
如果有人能告诉我何时使用以及它们的优点/缺点是什么,我们将不胜感激。
提前谢谢你。
【问题讨论】:
标签: javascript jquery backbone.js underscore.js