以下是我正在使用的Rails视图:
<%= current_user.name %>
<div class="row-fluid">
<script type="text/x-handlebars" data-template-name="my-template">
{{view App.ColumnView}}
</script>
</div>
当页面呈现时,我希望App.ColumnView
呈现的模板显示在行 - 流体div中。相反,它在我的应用程序布局的yield
语句之外呈现。这是我的应用程序布局(省略<html>
块:
<body class="container">
<header id="page-header">
<h1>App</h1>
</header>
<div class="content">
<%= yield %>
</div>
</body>
我的页面最终呈现如下:
<body class="container">
<header id="page-header">
<h1>App</h1>
</header>
<div class="content">
<%= yield %>
</div>
<div id="ember259" class="ember-view">
...
</div>
</body>
似乎ember正在将视图附加到<body>
标记,而不是在我的Rails视图中进行渲染。有没有办法使用我的Rails视图内联它?
答案 0 :(得分:5)
Ember应用程序的rootElement
属性默认为body
,因此Ember将所有内容附加到那里。
您当然可以指定显示所有应用程序的元素
window.App = Ember.Application.create({
rootElement: '#ember-app'
});
http://emberjs.com/api/classes/Ember.Application.html#property_rootElement
我很高兴这对你有帮助!