我在我的視圖中使用.ejs模板。但由於某些原因,視圖不會加載給定的模板。它返回undefined。這裏的代碼:模板不加載在Backbone.js應用程序 - 使用Yeoman構建
sandplate2.applicationView = Backbone.View.extend({
el: 'div',
template: _.template($("appl.ejs").html()),
initialize: function(){
console.log("Application view initialize");
_.bindAll(this, "render");
this.render();
},
render: function(){
console.log("Application view rendering");
this.$el.html(this.template());
return this;
}
});
我必須配置其他東西來加載模板?
我使用Yeoman構建了我的應用程序。我使用init和主幹生成器。
僅供參考 - 我嘗試加載的模板使用腳本元素加載到index.html中。
真棒。今晚會試試這個。 – jsf
順便說一句,你是如何安裝把手的?你有我可以看的樣品嗎?我運行yeoman安裝把手,它不會將它安裝在我的項目任何地方。 – jsf
我將一個AMD版本的Handlebars(因爲我使用RequireJS)放到了scripts/libs文件夾中,添加了一個handlebars條目到config.js的'paths'部分,然後像上面提到的那樣編輯了Backbone.LayoutManager.configure 。 – JamesOR