12
下划线中的外部模板
我使用Underscore模板。是否可以将外部文件作为模板? 在骨干视图中,我有: 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 ) }) 但它没有用。