ember.js - Ember access array controller's content from another controller -


i have 2 controllers: postscontroller , postcontroller. post route not nested under posts ( not want because want posts view replaced post view, not added it.)

this router looks like.

this.resource('posts', {path: '/'}, function(){     // this.route('index', {path: '/'});   });    this.resource('post', { path: 'posts/:id' }, function(){     this.route('show');   } 

now, postscontroller:

app.postsroute = ember.route.extend({   model: function(){     return this.store.find('post');   }, })  app.postscontroller = ember.arraycontroller.extend({   testproperty: "this test" })  

and postcontroller:

app.postroute = ember.route.extend({   model: function(params){     return this.store.find('post', params.id);   }, })  app.postcontroller = ember.objectcontroller.extend({   needs: ['posts'],   percentvalue: 100,   progressbarwidth: null,    advancepost: function(delta) {     var = this;     var posts = that.get('controllers.posts');     // debugger <-- questions concerned with.     ...   },    actions: {     nextpost: function() {       this.advancepost(1);     },     previouspost: function() {       this.advancepost(-1);     },   } }) 

so. postcontroller 'needs' postscontroller, , on action advancepost, needs access postscontroller's model (which supposed contain array of post objects.) @ point debugger is, variable posts accessed postscontroller. @ point, if run

posts.get('testproperty') // => gives "this test", correct. 

on chrome console, "this test". know have gained access posts controller itself. however, of following attempts:

posts.get('model') // gives []?? posts.get('content') // gives []?? 

returns empty array ( [] ).

i fail understand why. if have access posts arraycontroller, why not have access data? consequently, how gain access data?

i appreciate clarity on this.

first, if understand context, think should rather nest post under posts doing :

this.resource('posts', {path: '/'}, function(){ this.route('post', {path: '/:id'}); });

and then, since posts "parent" route, no longer need declare needs dependency in controller.

to access posts, apply following in route :

setupcontroller: function(controller, model) { this._super(controller, model); controller.set('posts', this.modelfor("posts").get("content")); }


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -