【发布时间】:2014-08-15 07:33:31
【问题描述】:
我想创建一个类似 UI 的仪表板。出于这个原因,我想在一个页面上呈现多个模板及其各自的模型。
我想,我可以使用 {{render}} 助手解决这个问题(请参阅http://emberjs.com/guides/templates/rendering-with-helpers/#toc_the-code-render-code-helper)
我已经渲染了模板,但其中没有数据。 您可以在 JsBin 上查看问题的最小示例:http://jsbin.com/vasezutoxege/2/edit?html,css,js,output
JsBin的一些sn-ps与这里的问题直接相关:
App.Router.map(function() {
this.resource('contacts', function() {
this.resource('contact', { path: ':contact_id'});
});
this.resource('records', function() {
this.resource('record', { path: ':record_id'});
});
});
对于每个路由器,我都有一个模型和一个模板。然后我想在我的应用程序的索引路由中显示路由:
<script type="text/x-handlebars" data-template-name="index">
<!-- link to contacts route is showing contacts template with model right -->
{{#link-to "contacts"}}Link to contacts route{{/link-to}}
<!-- this loads the template but without data -->
<div class="template">
{{render "contacts" contacts}}
</div>
...
</script>
如何在插座中呈现完整的模板及其模型数据?
感谢您的宝贵时间!
【问题讨论】:
-
您能否在您的问题中添加相关的代码部分?
-
嗨,我在帖子中添加了一些代码片段。但也请尝试 JsBin 示例。在那里,您可以在索引路线上看到空的绿色框。这意味着,
- 被渲染,但没有从模型中插入
- 。
标签: javascript ember.js handlebars.js