简体   繁体   English

Ember.js:内联把手模板在应用程序的根元素处呈现

[英]Ember.js: inline handlebars template renders at root element of app

On our page, we have an application "Index" associated with a root element of id "root". 在我们的页面上,我们有一个与索引根元素id“ root”相关联的应用程序“ Index”。 I'm attempting to insert a very simple handlebars template into the page inline (inside of this application). 我正在尝试将非常简单的车把模板插入页面内联页面(在此应用程序内部)。

<div id="root">
... 
    <script type="text/x-handlebars"> (this is nested about 5 levels into "root")
      {{foo}}
    <script>
...
</div>

However, when the page loads, I find the result is the metamorph placeholder moves to become the first child of "root" (even though in markup, it's quite nested). 但是,当页面加载时,我发现结果是变形占位符移动为“根”的第一个子项(即使在标记中,它也很嵌套)。

What's going on here? 这里发生了什么? No matter where I place this inline template, it keeps going to this place? 无论我将这个内联模板放在何处,它都会一直走到这个地方? How do I keep it where it is in markup? 如何将其保留在标记中?

The location the script templates is unrelated to where it's placed in the page. 脚本模板的位置与其在页面中的放置位置无关。 You could add it in the head of the document and it would be placed there as well, since it's the application template (due to it being unnamed). 您可以将其添加到文档的头部,也可以将其放置在文档的顶部,因为它是application模板(由于未命名)。 Structure of your app is defined using the router. 应用的结构是使用路由器定义的。

Example of nested routes: 嵌套路线示例:

http://emberjs.jsbin.com/OxIDiVU/151/edit http://emberjs.jsbin.com/OxIDiVU/151/edit

Additionally if you want your application to start at a different element you would set the rootElement on the App. 此外,如果您希望应用程序从其他元素开始,则可以在应用程序上设置rootElement

App.rootElement = '#fooId';

Example of rootElement: rootElement的示例:

http://emberjs.jsbin.com/bucasumo/1/edit http://emberjs.jsbin.com/bucasumo/1/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM