emberjs-1.7.0-beta.4 can't access another controller's content using needs api

34 Views Asked by At

I am trying to use the needs api to get access the content of the PagesController from my IndexController. But it is not working, the only way I have gotten it to work is to add an IndexRoute and load it through the model hook. Is there a way to use controller needs api to access the content of another controller. Here is the JSBIN: http://jsbin.com/gubuvuhi/1/edit

The PagesControllers:

  App.PagesController = Ember.ArrayController.extend({});

The IndexControler:

 App.IndexController = Ember.ArrayController.extend({
  needs: 'pages',

  fetchPages: Em.computed.alias("controllers.pages.content"), 

});

The PagesRoute:

App.PagesRoute = Ember.Route.extend({ 
   model: function(){
     return this.store.find('page');
   }
});

This index_template doesn't render fetchPages:

 <script type="text/x-handlebars" data-template-name='index'>

  <div class="container">
    <b>failed to display using needs api </b>
    <div>
     {{#each page in fetchPages }}
        {{page.navbar}}
     {{/each}}
  </div>

 </script>

But when I add an IndexRoute and change the IndexTemplate to this, it works & renders the right content:

  <script type="text/x-handlebars" data-template-name='index'>

  <div class="container">
    <b>failed to display using needs api </b>
    <div>
     {{#each page in model }}
        {{page.navbar}}
     {{/each}}
  </div>

 </script>

This is the IndexRoute, note that

 App.IndexRoute = Em.Route.extend({
   model: function(){
    return this.store.find('page');
   }
 });

You will see that this.store.find('pages') is repeated in both IndexRoute and PagesRoute, I want to avoid this by using needs api to get PagesController's content from the IndexController. Is there a way to do this. Here is the JSBIN: http://jsbin.com/gubuvuhi/1/edit

0

There are 0 best solutions below