2012-12-09 24 views
2

我试图在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'); 
      } 
     }) 
    }) 
}); 

+0

你能为此做一个jsFiddle吗?这对于发现问题将会非常有帮助,而且你更有可能得到答案。 – Aras

+0

一个jsFiddle会很有帮助,因为你发布的代码本身看起来是正确的。需要更多的上下文来帮助你:) – adivis

回答

5

如果它的任何帮助,我得到这个错误因为我连接的是Ember.ObjectController而不是Ember.Controller。

+0

它解决了我对同样的问题:)谢谢 – AyKarsi