1
I次BACKBONE.JSクライアント側のテンプレートを持っている:バックボーンクライアントテンプレートにモデルをバインド
<script id="calleeTemplate" type="text/x-jquery-tmpl">
<tr style="background-color: ${StatusColour}">
<td class="responder">${ContactFullName}</td>
<td class="status" style="width:200px">${Status}</td>
<td class="replied">${Replied}</td>
<td class="wauto">${Response}</td>
</tr>
</script>
これらのプロパティにバインドすることを可能にするために、私は、ビューのrenderメソッドを次のようしています。
App.Views.Callees = Backbone.View.extend({
initialize: function() {
},
el: $('#calleesStatuses'),
render: function() {
var col = _.map(this.collection.models, function (item) {
return item.attributes;
});
$('#calleesStatuses').html('');
$('#calleeTemplate').tmpl(col).appendTo(this.el);
}
});
モデルのアンダースコア_.map
関数を使用して属性を抽出する必要があります。なぜなら、バックボーンは.get("property")
を使ってプロパティ値を抽出しているからです。
これは私にとっては正しいとは思わないが、何か間違っているのだろうか?