我正在构建ember.js/rails应用程序。所有车把模板都存储在 .js 文件中。我想了解当路由器更改状态时它们如何插入到 DOM 中。Ember 的哪一部分执行此操作?我如何告诉 ember 放置模板?
现在我只能将我的模板附加到<body>
我有一个jsFiddle 在这里 http://bit.ly/MItOcl.
我知道设置rootElement
在 Ember.Application 上,但是我希望应用程序控制页面的其他元素。
车把 / 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();
ember.js中的当前实现附加ApplicationView
to the rootElement
的应用程序,请参阅here https://github.com/emberjs/ember.js/blob/541d085ae039a190d24213d1476de53029355bf9/packages/ember-application/lib/system/application.js#L157-166.
一种可能的解决方案是覆盖appendTo
你的ApplicationView
, see http://jsfiddle.net/pangratz666/m8L6Z/ http://jsfiddle.net/pangratz666/m8L6Z/:
JavaScript:
App.ApplicationView = Em.View.extend({
templateName: 'application',
appendTo: function(){
this._super('#content');
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)