Using multiple named outlets and a wrapper view with no content in Emberjs

Posted by user1889776 on Stack Overflow See other posts from Stack Overflow or by user1889776
Published on 2012-12-09T17:00:52Z Indexed on 2012/12/09 17:03 UTC
Read the original article Hit count: 329

Filed under:

I'm trying to use multiple named outlets with Ember.js. Is my approach below correct?

Markup:

<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 Code:

Here I set the content of the various controllers to data grabbed from a server and connect outlets with their corresponding views. Since the HomeController has no content, set its content to an empty object - a hack to get the rid of this error message:

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');
            }
        })
    })
});

?

© Stack Overflow or respective owner

Related posts about ember.js