ember.js - Reference RSVP hash from inside the same hash -


i'm trying load 2 different models on same route, found stack overflow explained can use ember.rsvp.hash() done, here i've done make work.

model: function(params) {     return ember.rsvp.hash({         flyer: this.store.find('flyer', params.flyer_id),         images: this.store.find('image', '-jrgar1tsaruw-_pijqx')     }); }, 

as can see have hard coded id of images record need load, should come returned flyer flyer.imagesid

but when error in console, stack trace...

error while processing route: flyers flyer not defined referenceerror: flyer not defined     @ model (http://localhost:4200/assets/flyer-creator.js:338:38)     @ emberobject.default.extend.deserialize (http://localhost:4200/assets/vendor.js:32872:19)     @ applyhook (http://localhost:4200/assets/vendor.js:55667:32)     @ object.handlerinfo.runsharedmodelhook (http://localhost:4200/assets/vendor.js:53668:22)     @ object.subclass.getmodel (http://localhost:4200/assets/vendor.js:53894:21)     @ __exports__.bind (http://localhost:4200/assets/vendor.js:55536:19)     @ trycatch (http://localhost:4200/assets/vendor.js:55993:16)     @ invokecallback (http://localhost:4200/assets/vendor.js:56005:17)     @ publish (http://localhost:4200/assets/vendor.js:55976:11)     @ http://localhost:4200/assets/vendor.js:37026:7 

is there way access flyer property that's returned hash in next property?

ember.rsvp.hash() avoid encoding actual promise order. when order important use promise chaining.

model: function(params) {    var self = this;    return this.store.find('flyer', params.flyer_id).then(function(flyer) {      return ember.rsvp.hash({        flyer: flyer,        images: self.store.find('image', flyer.get('imagesid'))      });    }); }, 

in special case use route dynamic param params.flyer_id, better way:

  • resolve flyer in model hook,
  • resolve images in aftermodel hook, based on model.

the reason model hook not fired when pass flyer model directly route {{link-to 'flyer' 'flyer' flyer}} or transitionto('flyer', flyer).

model: function(params) {   return this.store.find('flyer', params.flyer_id); },  aftermodel: function(flyer) {   var self = this;   // flyer model resolved   return this.store.find('image', flyer.get('imagesid')).then(function(images) {      var controller = self.controllerfor( self.get('controllername') );      controller.set('images', images);      // or 2 steps:       // 1) self.set('images', images) here      // 2) implement setupcontroller hook, has controller param    }); } 

ps if flyer belongsto image use promise

flyer.get('image') 

instead of

this.store.find('image', flyer.get('imageid')) 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -