我试图在Ember.js中使用多个命名插座。我的方法是否正确?在Emberjs中使用多个命名插座和无内容封装视图
标记:
<script type="text/x-handlebars" data-template-name="application">
<div id="mainArea">
{{outlet main_area}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="home">
<ul id="sections">
{{outlet sections}}
</ul>
<ul id="categories">
{{outlet categories}}
</ul>
</script>
<script type="text/x-handlebars" data-template-name="sections">
{{#each section in controller}}
<li><img {{bindAttr src="section.image"}}></li>
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name="categories">
{{#each category in controller}}
<img {{bindAttr src="category.image"}}>
{{/each}}
</script>
JS代码:
在这里,我设置各种控制器数据的内容从服务器抓住并与它们的对应的观点连接插座。由于HomeController中没有的内容,其内容设置为空对象 - 一个黑客获得摆脱这种错误消息:
Uncaught Error: assertion failed: Cannot delegate set('categories' ) to the 'content' property of object proxy : its 'content' is undefined.
App.Router = Ember.Router.extend({
enableLogging: false,
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router){
router.get('sectionsController').set('content',App.Section.find());
router.get('categoriesController').set('content', App.Category.find());
router.get('applicationController').connectOutlet('main_area', 'home');
router.get('homeController').connectOutlet('home', {});
router.get('homeController').connectOutlet('categories', 'categories');
router.get('homeController').connectOutlet('sections', 'sections');
}
})
})
});
你能为此做一个jsFiddle吗?这对于发现问题将会非常有帮助,而且你更有可能得到答案。 – Aras
一个jsFiddle会很有帮助,因为你发布的代码本身看起来是正确的。需要更多的上下文来帮助你:) – adivis