나는 밑줄 템플릿을 사용 합니다. 외부 파일을 템플릿 으로 첨부 할 수 있습니까?
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 ) })
하지만 작동하지 않았습니다.