Backbone.js 使用带主干的模板
Helllo,这可能是一个常见的问题,但我没有找到合适的答案 我有一个html文件:header.html,其中包含我想要显示的头 这是我的脊梁骨Backbone.js 使用带主干的模板,backbone.js,Backbone.js,Helllo,这可能是一个常见的问题,但我没有找到合适的答案 我有一个html文件:header.html,其中包含我想要显示的头 这是我的脊梁骨 el: $(".header"), initialize: function () { this.render(); }, render: function () { var template = _.template( $("#header_template").html(), {} ); this.$el.html(
el: $(".header"),
initialize: function () {
this.render();
},
render: function () {
var template = _.template( $("#header_template").html(), {} );
this.$el.html( template );
},
当我将代码放入java脚本模板中时,它可以工作:
<script type="text/template" id="header_template">
code of header.html goes here
</script>
header.html的代码在这里
但当我这样使用它时:
<script type="text/template" id="about_template" src="header.html"></script>
即使firebug看到模板中的代码,它也会停止工作
有人能告诉我我的错误是什么以及如何解决它吗?组织模板的干净方法是创建一个子文件夹
tpl
。在这里,您可以添加所有.html
文件
Coenraets将此方法与templateloader
函数结合使用
然后,在引导主干应用程序之前,将模板加载到内存中
tpl.loadTemplates(['header', 'wine-details', 'wine-list-item'], function() {
app = new AppRouter();
Backbone.history.start();
});
这可能会有帮助:所以我们要么把代码放在变量中,要么使用get方法?有更优雅的解决方案吗?