【发布时间】:2014-04-14 12:53:16
【问题描述】:
我有一个视图,其模板如下所示:
<script type="text/template" id="template">
<div id="<%=cid=>"></div>
<label><%= label %></label>
<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search" />
</script>
我需要使用模型数据来渲染这个模板,所以我做了以下事情:
render: function () {
var template = _.template( $("#template").html(), this.model.toJSON());
this.$el.html( template );
return this;
}
但不幸的是 this.model.toJSON() 没有将 cid (clientId) 传递给我的模板。你能解释一下我如何在我的模板中访问 cid 以及你如何处理这个事情吗?
【问题讨论】:
标签: backbone.js model-view-controller underscore.js template-engine underscore.js-templating