2
我設法讓以下代碼正確地呈現模板。 home
是一個預編譯的模板名稱。如何使骨幹模板更簡單
app.HomeView = Backbone.View.extend({
el: '#main',
template: 'home',
render: function(){
var self = this;
dust.render(this.template, {name:'world'}, function(err,out){
self.$el.html(out);
});
return this;
}
});
然而,這不是很整齊搞糟與self
和灰塵回調的東西,因爲我有很多的模板。
是否可以清理它,就像使用下劃線模板一樣(如下所示)?
template: _.template($('#some-template').html()),
render: function(){
this.$el.html(this.template({name:'world'}));
return this;
}
感謝您指出'bind'。 –