我试图让我的应用程序在路由器初始化时加载所有数据。加载数据工作正常,问题是当我尝试去一个需要数据太快的路线时它还没有加载数据。如何让数据首先加载并等到路由器完全初始化以处理我的路由视图“计划”?
window.IrdbWeb = Backbone.Router.extend({
routes: {
'': 'home',
'schedule/': 'schedule'
},
initialize: function() {
window.encoderStream = new Stream();
window.scheduleLibrary = new Schedules();
window.recordingLibrary = new Records();
$.when(window.encoderStream.fetch(),window.recordingLibrary.fetch(), window.scheduleLibrary.fetch()).done(function(){
this.scheduleLibraryView = new ScheduleLibraryView({
collection: window.scheduleLibrary
});
});
// Player model
this.player = new Player();
this.playerView = new PlayerView({
player: this.player
});
$('div#overlay').fadeOut(800);
},
home: function() {
},
schedule: function() {
$("#info").empty().append(this.scheduleLibraryView.render().el);
}
});
window.App = new IrdbWeb();
Backbone.history.start();
如果我从家里去 - >安排它工作,因为路线有时间初始化视图。