如何处理加载结束事件?

时间:2015-01-14 18:09:59

标签: ember.js promise loading

我有以下测试应用程序,实现loading事件:

App = Ember.Application.create();

function delayedPromise(delay, value) {
    delay = delay || 3000;
    value = value || { msg: 'Delayed promise has been fulfilled' };
    var promise = new Ember.RSVP.Promise(function(resolve) {
        Ember.run.later(function() {
            console.info('Delayed promise has been fulfilled');
            resolve(value);
        }, delay);
    });
    return promise;
}

App.ApplicationRoute = Ember.Route.extend({
  beforeModel: function() {
    return delayedPromise();
  },

  actions: {

    loading : function() {
      $.blockUI();
    },

  }
});

哪个工作符合预期:用户被loading事件阻止。

如何取消阻止用户界面($.unblockUI())?是否有loadingFinished(或类似的)操作,只要所有模型都已完成解析,我就可以实现它?

工作jsbin here

1 个答案:

答案 0 :(得分:2)

按照Legacy Loading Route的例子,您可以:

App.ApplicationRoute = Ember.Route.extend({
  beforeModel: function() {
    return delayedPromise();
  },

  actions: {

    loading : function() {
      $.blockUI();
      this.router.one('didTransition', $, 'unblockUI');
    },

  }
});