我試圖將這個jQuery模板轉換爲一個underscorejs模板,但沒有意義爲什麼它不工作。誰能解釋爲什麼?從舊的轉換下劃線模板的錯誤
el: $('#contents'),
template: _.template(MenuTemplate),
//template: $('#item-tmpl').template(),
render: function()
{
this.$el.empty();
//$.tmpl(this.template, this.model.toArray()).appendTo(this.el);
// Old jquery template
//this.$el.html(this.template(this.model.toArray()).appendTo(this.el));
//underscore template
return this;
}
什麼不工作?我不明白你使用模板並設置到根元素的技巧(不需要調用appendTo)。請參閱[這裏](http://backbonejs.org/#View-render)。 – WiredPrairie 2013-03-15 10:49:25