用一个大的外部文件与Backbone.js的许多JavaScript的模板? [英] use one large external file for many javascript templates with backbone.js?

查看:104
本文介绍了用一个大的外部文件与Backbone.js的许多JavaScript的模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务了骨干应用两种不同的HTML页面。到现在为止,我已经把所有的JS模板,每个模板对应的HTML文件里。

I have two different HTML pages that serve up backbone apps. Up until now, I have put all the js templates inside of each respective HTML file.

现在,我重构了一下,想和大家分享的文件之间的一些骨干看法。当加载不能找到一个js模板的观点,整个应用程序会报错了。我知道要合并这两个是有外部JS模板,使用EJS例如,并且每个文件1模板的正确方法,但是,我想只是嵌入1巨大的HTML文件 <脚本类型=文本/模板'> 分享我的2页之间的模板HTML文件。这可能吗?我试图让外部JS模板和AJAX,并将其写入头,但骨干网的观点仍然无法找到他们。

Now, I'm refactoring a bit and would like to share some backbone views between files. When loading a view that can't find a js template, the whole app will error out. I know the proper way to merge these two would be to have external js templates, using EJS for example, and have 1 template per file, however, I'd like to just have one huge HTML file with embedded <script type='text/template'> and share the template HTML file between my 2 pages. Is this possible? I tried getting the external js templates with AJAX and writing them to the head, but backbone views still can't find them.

没有任何人选择将与它的JavaScript许多模板的文件?我也发现我的文件无法管理的数量打开,当我使用EJS。任何帮助将是最AP preciated。

Does anyone else choose to have a file with many javascript templates in it? I also find that I have an unmanageable number of files open when I use ejs. Any help would be most appreciated.

推荐答案

我使用一个额外的JavaScript / CoffeeScript的文件,使用的下划线的模板来打理一切。这种方式可以包括模板,并把它们放到尽可能少(或多个)的文件,你想。

I use an extra javascript/coffeescript file and use underscore's templating to take care of everything. This way you can include the templates and put them into as few (or many) files as you would like.

这篇关于用一个大的外部文件与Backbone.js的许多JavaScript的模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆