Backbone, trigger an events when all is loaded

微笑、不失礼 提交于 2019-12-04 17:11:23
test: function() { 
    $.when(
        this.Models_1.fetch({silent: YES}), // silent will prevent triggering any events on reset or add
        this.Models_2.fetch({silent: YES}),
        this.Models_3.fetch({silent: YES})
    ).then(_.bind(function() {
        this.Models_1.trigger('reset'); // manually trigger events in sequence you want
        this.Models_3.trigger('reset');
        this.Models_2.trigger('reset');
    }, this));
}

Not sure where you are going with your deferred events. Backbone already has a way to do this.

In your view, bind the event "refresh" from the collection to the view render function. Whenever you will call fetch on the collection, the refresh event will be triggered and your view rerendered.

Perhaps underscores defer is the method you're looking for?

Defers invoking the function until the current call stack has cleared, similar to using setTimeout with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without blocking the UI thread from updating.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!