简体   繁体   中英

ember add an promise to a rsvp promise because of action

i have a route that returns several models as such

FriendEnemyRouter

model: function() {
    return Ember.RSVP.hash({
        friends: this.store.find('People', ...),
        enemies: this.store.find('People', ..),

On the same router theres an action (Its on the router because it does store 'things')

actions: {
     findMoreFriends: function(param, param) {
         var newFriends = this.store.find('People', ..); 
         var newPromise = this.controller.get('model'); //OK. Inspecting sees above friends and enemies. What type is it?

         model.set("newFriends": newPromise); // throws an exception
         //-- or --
         model.newFriends = newPromise; // no exception but observer (computer property) on the controller is not fired.
     }
 }

Ultimately i wish this computed property on the controller to fire

 FriendEnemyController

  computedNewFriends: function() {
       ....
   ).property('newFriends');

What is the procedure for adding new promises to rsvp promises...not even sure the object types...

         model.set("newFriends": newPromise); // throws an exception
         model.newFriends = newPromise; // no exception but clearly doesnt notify observer/property

RSVP.hash resolves a POJO , meaning it doesn't extend Ember.Object . As such set and get aren't defined on the object itself. You can use Ember.set and Ember.get on objects which aren't Ember Objects, and it will trigger computed properties.

Ember.set(model, 'newFriends', newPromise)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM