How to update Ember's model periodically (such as in setInterval)?

前端 未结 2 579
迷失自我
迷失自我 2020-12-09 04:23

I have an Ember application whose model comes from an Ajax call. The first call works great, I have the model hook of the Ember.Route return a promise to the Aj

相关标签:
2条回答
  • 2020-12-09 04:38

    I think this is a good use case for Ember.run.later, which limits the frequency of function calls.

    You could just add a refresh to your model, similar to this:

    App.Model = DS.Model.extend({
       poll: function() {
          var _this = this;
          Ember.run.later( function() {
             _this.reload(); 
             _this.poll();
          }, 500);
       }.observes('didLoad'),
    });
    
    0 讨论(0)
  • 2020-12-09 04:40

    If you are not using Ember data you can simply add a recursive setTimeout or setInterval in you controller and set the model property. Here is a simple example setting the model from a UI event.

    If you are using ember-data I think the following threads have more accurate solutions:

    • Ember model reloading in interval
    • How to reload an ember data record?
    0 讨论(0)
提交回复
热议问题