【发布时间】:2013-03-08 16:16:42
【问题描述】:
我正在尝试在使用 mustache.js 构建的模板上呈现主干集合。问题是我无法在模板中获取模型的 cid。我的代码是
<div class="phone span4">
<h5> Phone Appointments</h5>
{{ _.each(slots, function(slot) { }}
{{ if(slot.aptType == "P"){ }}
<h6 cid="{{=slot.cid}}" aptId="{{=slot.aptId}}"> {{=slot.beginTime}} - {{=slot.endTime}} </h6>
{{ } }}
{{ }); }}
</div>
从上面的代码中,我可以得到 aptId、beginTime 和 end Time,但不能得到 Cid。在模板上渲染时如何从集合中获取模型的Cid?
我的视图渲染方法看起来像这样
render:function(){
var template = _.template($("#slot-display-template").html());
compiledTmp = template({slots: this.collection.toJSON()})
this.$el.append(compiledTmp);
}
使用 cid 作为模型的唯一标识符有什么缺点吗?
提前致谢!!!
【问题讨论】:
-
为什么需要 cid 在 html 中?如果您有模型的 id(看起来 aptId 是 idAttribute?),您可以在集合中找到它,
collection.get(modelId)。
标签: javascript templates backbone.js mustache