0
Helllo,這可能是一個常見問題,但我沒有找到合適的答案。在Backbone中使用模板
我有一個HTML文件:header.html中包含我要顯示的標題
這裏是我的Backbone.View
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>
但是,當我使用這種方式:
<script type="text/template" id="about_template" src="header.html"></script>
即使Firebug看到模板內的代碼,它也會停止工作。
有人能告訴我有什麼錯誤,以及如何解決它
這可能會有所幫助:http://stackoverflow.com/questions/8366733/external-template-in-underscore –
所以我們要麼把代碼中的變量或使用GET方法? – user3412802
有沒有更優雅的解決方案? – user3412802