模板不加载在Backbone.js的应用程序 - 内置使用约曼 [英] Template not loading in a Backbone.js app - built using Yeoman
问题描述
我使用在我看来一个.ejs模板。但由于某些原因的看法不会加载指定的模板。它返回undefined。这里的code:
I am using an .ejs template in my view. But for some reason the view does not load the given template. It returns undefined. Here's the code:
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;
}
});
我一定要配置别的东西,以加载模板?
Do I have to configure something else in order to load a template?
我使用约曼结构我的应用程序。我用了init和骨干发电机。
I structured my app using Yeoman. I used the init and backbone generators.
仅供参考 - 我试图加载模板使用脚本元素加载中的index.html
FYI - The template I am trying to load is loaded in the index.html using a script element.
推荐答案
如果你建立了它使用约曼,看看app.js看到,如果你正在使用的 Backbone.LayoutManager 。您可能需要修改配置那里EJS工作。默认情况下,我认为它应该被期待下划线模板。
If you built it using Yeoman, take a look at app.js to see if you are using Backbone.LayoutManager. You might have to change the configuration there for EJS to work. By default, I think it should be expecting Underscore templates.
我使用把手,然后我更新我的app.js看起来是这样的:
I'm using Handlebars and I updated my app.js to look like this:
Backbone.LayoutManager.configure({
manage: true,
paths: {
layout: "templates/layouts/",
template: "templates/"
},
fetch: function(path) {
path = path + ".html";
if (!JST[path]) {
$.ajax({ url: app.root + path, async: false }).then(function(contents) {
JST[path] = Handlebars.compile(contents);
});
}
return JST[path];
}
});
我还添加了车把模块的定义()调用,传递'把手'作为参考。您可能需要做EJS类似的事情。
I also added Handlebars to the module's define() call, passing in 'Handlebars' as a reference. You might need to do something similar for EJS.
这篇关于模板不加载在Backbone.js的应用程序 - 内置使用约曼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!