3

如果在 index.html 文件中声明了我的应用程序模板,它们就可以工作。但是,我想将所有模板保存在不同的 html 文件中,例如 -AppTmpl.html

<!-- SidebarView Template -->
<script id="sideBarTmpl" type="text/template">
   <div class="inner_div"><img src="images/com_logo.png"></div>
   <div class="inner_div"><img src="images/adv_index.png"></div>
</script> 

<!-- HeaderView Template -->
<script id="folderDivTmpl" type="text/template">
   <div id="div_<%= menu_sequence %>"></div>
</script>

我正在使用下划线模板。但问题是这些模板不能通过下划线访问。比如,this.template = _.template($("#headerTmpl").html(), this.model.toJSON());

所以我需要做的就是在 index.html 或其他东西中包含“AppTmpl.html”文件。有什么解决办法吗?

提前致谢 !

4

1 回答 1

2

我将requireJS文本插件一起使用

然后,您可以根据需要使用 requireJS 加载它:

require(['text!templates/AppTmpl.html'],function(AppTemplate){

     this.template = _.template(AppTemplate);

});
于 2012-09-20T07:26:54.783 回答