backbone.js - Is it possible to pass cid field in template? -
i have view have template looks following:
<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>
and need render template using model data, following:
render: function () { var template = _.template( $("#template").html(), this.model.tojson()); this.$el.html( template ); return this; }
but unfortunately this.model.tojson() doesn't pass cid (clientid) template. may explain how access cid in template , how handle thing?
tojson
clones attributes
array. that's why there's no cid. if need cid model, may mix in template object:
var templatedata = _.extend(this.model.tojson(), { cid: this.model.cid }); var template = _.template( $("#template").html(), templatedata);
but if need unique id div
- recommend use _.uniqueid()
Comments
Post a Comment