我使用Underscore template。可以将外部文件附加为模板
在Backbone View中,我有:
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>
它工作得很好。但是我需要外部模板。我试着:
<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 ) })
但它并没有起作用。
https://stackoverflow.com/questions/8366733
复制相似问题