【发布时间】:2012-06-24 15:36:39
【问题描述】:
我正在构建一个 ember.js/rails 应用程序。所有车把模板都存储在 .js 文件中。我想了解当路由器更改状态时它们是如何插入到 DOM 中的。 ember 的哪个部分会这样做?我如何告诉 ember 放置模板?
现在我只能将我的模板附加到<body> 我有一个jsFiddle here。
我知道在 Ember.Application 上设置 rootElement,但是我希望应用程序控制页面的其他元素。
把手/HTML:
<script type="text/x-handlebars" data-template-name="application">
<h2>I'm the content</h2>
<p>This should be inbetween the header & footer</p>
<p><strong>time</strong> {{time}}</p>
</script>
<header>
<h1>Application</h1>
</header>
<article>
<div id="content"></div>
</article>
<footer>
<a href="http://blog.deanbrundage.com" target="_blank">by Dean</a>
</footer>
JavaScript:
window.App = Ember.Application.create();
App.Router = Em.Router.extend({
initialState: 'root.home',
root: Em.Route.extend({
home: Em.Route.extend({
view: App.ApplicationView
})
})
});
App.ApplicationController = Em.Controller.extend({
time: Date()
});
App.ApplicationView = Em.View.extend({
templateName: 'application'
});
App.initialize();
【问题讨论】: