0
我在Firefox中遇到了一個奇怪的問題。我們正在加載一個頁面,同時調用Routers.initializeRouters();發送ajax請求來獲取數據,loadFormSuccessHandler函數將響應填充到視圖中。Backbone.js的Ajax在Chrome和Firefox中調用不同的行爲
在Chrome的情況下,Ajax請求會等待視圖被初始化,然後數據會通過ajax響應填充到視圖中。
在Firefox的情況下,Ajax請求獲取數據並開始填充視圖,並失敗,因爲一些視圖仍未初始化。
如何在填充數據之前通知ajax請求等待視圖初始化。
任何指針都會有幫助。
Main.js
var Main = {
treeView : null,
formView : null,
mainTabBarView : null,
currentFieldView : null,
designModeViewPointer : null,
carousel : null,
advancedControlsView : null,
renderUI : function() {
Templates.loadTemplateList();
Utility.initializeFieldHandlerMap();
Views.showBody();
Routers.initializeRouters();
var form = new Models.Form();
this.formView = Views.showForm('formDetailsDiv', form);
this.treeView = new Views.TreeView({
el : $('#controlsTreeDiv'),
model : null
});
this.treeView.getTree().attachEvent("onDblClick",
ControlBizLogic.formTreeNodeClickHandler);
Main.mainTabBarView = new Views.TabBarView({
el : $('#csdOperationsContainer'),
model : null
});
Views.showControlTab('control');
this.carousel = $('#controlTypesSlider');
this.carousel.tinycarousel();
Main.advancedControlsView = new Views.AdvancedPropertiesTabView({
el : $('#advancedControlProperties'),
model : null
});
// init design mode
Main.designModeViewPointer = new Views.DesignMode({
el : $("#design")
});
Routers.designModeOnBeforeDragEvent();
Routers.designModeOnDragEvent();
}
}
Main.renderUI();
與Ajax調用響應
loadForm : function(_id, edit) {
$("#formWaitingImage").show();
if (Main.formView == null) {
Main.formView = Views.showForm('formTab',
new Models.Form({
"id" : _id
}));
}
Main.formView.getFormModel().set({
id : _id
});
GlobalMemory.editForm = (edit == "true");
Main.formView.getFormModel().fetch({
url : 'csdApi/form/' + _id + "/" + edit,
success : this.loadFormSuccessHandler
});
// save as
},
loadFormSuccessHandler : function(model, response) {
var formId = model.get('id');
if (formId != undefined && formId != null) {
GlobalMemory.editForm = true;
}
Routers.formEventsRouterPointer.updateUI(model);
Routers.formEventsRouterPointer.loadFormulae(Main.formView
.getFormModel(), "", "");
AdvancedControlPropertiesBizLogic
.loadSkipRules(Main.formView.getFormModel());
Main.formView.getFormModel().set({
skipRules : model.get('skipRules'),
id : model.get('id')
});
Main.advancedControlsView.setTableCss('formulaTable');
// Main.mainTabBarView.loadFormSummary();
Main.mainTabBarView.getFormSummaryView().displayFormInfo(
model.getFormInformation());
$("#formWaitingImage").hide();
// save form
if (!GlobalMemory.editForm) {
$('#saveForm').prop("value", " Save As ")
}
},