我正在构建一个ember.js/rails应用程序.所有车把模板都存储在.js文件中.我想了解当路由器改变状态时它们如何插入到DOM中. 这个部分是什么呢? 如何告诉ember放置模板?
现在我只能将我的模板附加到<body>我有一个jsFiddle这里.
我知道设置rootElementEmber.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>
Run Code Online (Sandbox Code Playgroud)
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();
Run Code Online (Sandbox Code Playgroud)
Ember.js中的当前实现将应用程序附加ApplicationView到rootElement应用程序,请参见此处.
一种可能的解决方案是覆盖appendTo你的ApplicationView,请参阅http://jsfiddle.net/pangratz666/m8L6Z/:
JavaScript:
App.ApplicationView = Em.View.extend({
templateName: 'application',
appendTo: function(){
this._super('#content');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1313 次 |
| 最近记录: |