あなたはその事実を利用することができます
- jQuery オブジェクトは DOM 要素のリストです
- バックボーンは一意の DOM ノードを必要としません (少なくとも私が知る限り)
this.$el
ビューでは、必要なノードにすることができます
それを念頭に置いて、テーブルを一度にレンダリングし ( BackboneJS Rendering Problemsを参照してください。より高速で、おそらくはるかに簡単です)、モデルに関連付けられたテーブル セルにサブビューを適用できます。選択にはクラス名を使用しましたが、各行の n 番目の要素のセレクターが機能するはずです。
テンプレート
<table>
<thead>
<tr>
<th></th>
<% _(children).each(function(model) { %>
<th><%= model.id %></th>
<% }); %>
</tr>
</thead>
<tbody>
<% _(properties).each(function(prop) { %>
<tr>
<td><%= prop %></td>
<% _(children).each(function(model) { %>
<td class="<%= model.cid %>"><% print(model[prop]); %></td>
<% }); %>
</tr>
<% }); %>
</tbody>
</table>
意見
ListView = Backbone.View.extend({
initialize: function(opts) {
this.options = opts;
},
render: function () {
var data, html, $table, template = this.options.template;
data = this.collection.map(function (model) {
return _.extend(model.toJSON(), {
cid: model.cid
});
});
html = this.options.template({
children: data,
properties: ['id', 'name']
});
$table = $(html);
this.collection.each(function (model, ix) {
var $el = $table.find("." + model.cid),
subview = new ItemView({
el: $el,
model: model
});
});
this.$el.empty();
this.$el.append($table);
return this;
}
});
このデモhttp://jsfiddle.net/nikoshr/psasT/12/で確認できるように、各列は専用のビューによって処理されます。