我尝试在我的网络应用程序上将 EmberJS 从 pre1 更新到 pre2,但我注意到它将所有车把模板作为最后一个主体元素,有时根本不这样做。
I've 创建一个重现 http://emberjs-pre2-bug.staticloud.com/使用 starter-kit 进行简单修改,将 div 放在模板之前和之后,以显示模板将添加到错误的位置。
使用 pre1 运行同一页面,一切正常。
索引.html
....
<body>
<div>this is before the template</div>
<script type="text/x-handlebars" data-template-name="application">
<h1>Hello from Ember.js</h1>
</script>
<div>this is after the template</div>
....
text/x-handlebars 脚本标签定义了一个 Handlebar 模板,与您将其放置在页面中的位置(头部、正文中的任何位置)无关。
在上面的代码中,您定义了模板ApplicationView
。由于您使用路由器,ember 会自动创建ApplicationView
and appends将其添加到 Ember 应用程序的根元素。默认情况下,rootElement
是身体:
App.ApplicationView.create().appendTo(rootElement) // default rootElement = 'body'
and the appendTo
方法使用 jQueryappendTo http://api.jquery.com/appendTo/:
this.$().appendTo(target)
因此,如果你想控制applicationView
插入后您需要设置rootElement
在 App 实例中,如下所示:
window.App = Ember.Application.create({
rootElement: '#insert_my_app_here'
});
...
<body>
<div>this is before the template</div>
<script type="text/x-handlebars" data-template-name="application">
<h1>Hello from Ember.js</h1>
</script>
<div id="insert_my_app_here"></div>
<div>this is after the template</div>
</body>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)