首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >下划线中的外部模板

下划线中的外部模板
EN

Stack Overflow用户
提问于 2011-12-03 17:22:50
回答 12查看 79.8K关注 0票数 121

我使用Underscore template。可以将外部文件附加为模板

在Backbone View中,我有:

代码语言:javascript
复制
 textTemplate: _.template( $('#practice-text-template').html() ),

 initialize: function(){                                            
  this.words = new WordList;            
  this.index = 0;
  this.render();
 },

在我的html中是:

代码语言:javascript
复制
<script id="practice-text-template" type="text/template">
   <h3>something code</h3>
</script>

它工作得很好。但是我需要外部模板。我试着:

代码语言:javascript
复制
<script id="practice-text-template" type="text/template" src="templates/tmp.js">

代码语言:javascript
复制
textTemplate: _.template( $('#practice-text-template').load('templates/tmp.js') ),

代码语言:javascript
复制
$('#practice-text-template').load('templates/tmp.js', function(data){ this.textTemplate = _.template( data ) })

但它并没有起作用。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8366733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档