0
我有一個帶有兩個項目的視口:一個認證表單和一個選項卡面板。 在這個視口的initComponent方法中,我調用一個函數來檢查用戶是否輸入了他的登錄名和密碼。使用setActiveItem時的白色屏幕
如果沒有,則會顯示身份驗證表單,當他單擊登錄按鈕時,會顯示選項卡面板。
但是,如果有存儲的憑據,我希望應用程序自動切換到選項卡面板。
這是我想要做的:
app.views.Viewport = function (config) {
Ext.apply(this, config);
this.user = null; // Setter par le checkLogin !
this.bottomTabs = new Ext.TabPanel({
tabBar: {
dock: 'bottom',
layout: { pack: 'center' }
},
items:[...],
layout: 'fit',
cardSwitchAnimation: false,
});
this.userLogin = new app.views.UserLogin();
//constructor
app.views.Viewport.superclass.constructor.call(this, {
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'fade',
items: [
this.userLogin,
this.bottomTabs
]
});
};
Ext.extend(app.views.Viewport, Ext.Panel, {
initComponent: function() {
app.views.Viewport.superclass.initComponent.call(this);
this.initialCheck();
},
initialCheck: function(){
console.log('init');
var credentials = window.localStorage.getItem("neroApp_credentials");
if (credentials == null || credentials == "reset") {
console.log('no creds');
this.setActiveItem(this.userLogin); // ***
}
else {
console.log('creds');
Ext.Ajax.defaultHeaders = {'Authorization':"Basic " + credentials};
this.checkLogin();
}
},
checkLogin: function() {
console.log('checkLogin');
Ext.Ajax.request({
url: app.stores.baseAjaxURL + '&jspPage=%2Fajax%2FgetUser.jsp',
scope: this,
success: function(response, opts) {
console.log('success');
var user = Ext.decode(response.responseText);
this.user = user;
this.actualites.actualitesList.refreshActu(this.user, parseInt(window.localStorage.getItem("newsPerLoad")));
this.setActiveItem(this.bottomTabs, { type: 'fade', duration: 500 });
},
failure: function(response, opts) {
console.log('failure');
}
});
},
resetLogin: function() {
window.localStorage.setItem("neroApp_credentials", "reset");
Ext.Ajax.defaultHeaders = {'Authorization':"Basic RESET_Credentials"};
}
});
但我發現了一個白色的屏幕上,因爲*線的啓動。我猜測它被觸發得太早可能是因爲checkLogin函數中的setActiveItem工作正常。
有人有一個想法,爲什麼這個setActiveItem引發錯誤?
感謝