简体   繁体   中英

Ember.RSVP.hash reload internal promises

I have an Ember.RSVP.hash object being returned from the model hook in the route object. However, I'd like to periodically pull the data from the server and "refresh" or reload all the data with the new data from the server. How can this be done? Say it looks something like this:

model: function(params) {

        return new Ember.RSVP.hash({
            firstProp: Ember.$.getJSON(baseURL + 'firstProp/'),
            secondProp: Ember.$.getJSON(baseURL + 'secondProp/'),
            thirdProp: Ember.$.getJSON(baseURL + 'thirdProp/'),
        });
    }

and I want to be able to do something like

poll: function() {
      var _this = this;
      Ember.run.later( function() {
         _this.reload(); 
         _this.poll();
      }, 500);
   }.observes('didLoad')

sort of thing, except I can't just call reload because I'm not using ember-data but rather using jQuery to pull the properties into an Ember.RSVP.hash . So how do I reload each of the component properties?

You can use the route's refresh method to trigger the model hook again.

If you want to call it from the controller, you could expose the method with a route action.

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