所以我一直想知道,如果我将所有模板写入一个文件中,Ember 会在加载应用程序时立即加载所有这些模板吗?
比如说,我在 index.html
<! -- Added all dependecies of Ember -->
<script type="text/x-handlebars" >
This is application template
</script>
<script type="text/x-handlebars" id="about">
This is about template
</script>
还有我的 application.js
App = Ember.Application.create();
App.Router.map(function(){
this.resouce('about');
});
假设我访问了 index.html
那么此时 about
模板是否已加载? ,我的意思是我自然地假设它 GET
index.html
页面并从中提取 Handlebars 模板,以便 index.html
中定义的所有模板code> 应在应用程序启动时加载。这是正确的吗? ,将不同的模板放入不同的文件中可以纠正这个问题吗?
最佳答案
是的,您的所有模板都将通过上述方式在启动时可用。
如果您只想分离模板进行开发。只需将模板分成不同的“hbs”文件并使用 grunt precompiler任务会将所有模板编译为单个 js 文件,您可以将其包含在 index.html 中。大多数 ember 应用程序只是预编译并连接所有模板和 js 文件。
如果您考虑延迟加载模板文件,您可能需要自己实现该机制。 Matthew Beale explains on lazy loading stuff in ember .
对于应用程序结构和组织,您应该真正研究一下 ember-cli .
关于javascript - Ember : Loading all template at once,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721136/