我已经准备好 html 标记,这不会改变,我只想在这个标记中添加/更新变量。
我如何使用主干和下划线来做到这一点?
我尝试了以下方法,
骨干:
testView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
var variables = {reqNumber: 10};
/*This is where I'm having problems, how do I use only variables in my template??
* How do I write this next line
*/
var template = _.template(this.$el.html(), variables);
this.$el.html(template);
}
});
var test_view = new testView({ el: $("div.container") });
HTML:
<a href="#">
<i class="icon-home icon-white"></i>
Requests <span class="badge badge-warning"><%= reqNumber %></span>
</a>