我使用 Underscore template。是否可以附加一个 作为模板的外部文件?
在 Backbone 视图中,我有:
textTemplate: _.template( $('#practice-text-template').html() ),
initialize: function(){
this.words = new WordList;
this.index = 0;
this.render();
},
在我的 html 中是:
<script id="practice-text-template" type="text/template">
<h3>something code</h3>
</script>
It works well. But 我需要外部模板. 我试着:
<script id="practice-text-template" type="text/template" src="templates/tmp.js">
或者
textTemplate: _.template( $('#practice-text-template').load('templates/tmp.js') ),
或者
$('#practice-text-template').load('templates/tmp.js', function(data){ this.textTemplate = _.template( data ) })
但是没有成功。