[英]ExtJS4 - MVC Store, retrieve data
我有一個帶有商店,模型和視圖(工具欄)的控制器:
Ext.define('Cc.controller.Headers', {
extend: 'Ext.app.Controller',
stores: ['User'],
models: ['Agent'],
views: ['Header'],
refs: [
{ ref: 'navigation', selector: 'navigation' },
{ ref: 'tabPanel', selector: 'tabpanel' },
{ ref: 'head', selector: 'head' },
{ ref: 'logoutButton', selector: 'head button[action=logout]'},
{ ref: 'helpButton', selector: 'head button[action=help]'}
],
init: function() {
this.control({
'head button[action=logout]': {
beforerender: this.initLogoutButton,
click: this.onClickLogoutButton
},
'head button[action=help]':{
click: this.onClickHelpButton
}
});
},
initLogoutButton: function(a){
var store = this.getUserStore(),
button = this.getLogoutButton();
store.load();
var user = this.getAgentModel();
button.setText('Logout ['+user.get('lastname')+']');
console.log(store.count());
},
onClickLogoutButton: function(view, record, item, index, e){
alert('déconnexion');
},
onClickHelpButton: function(view, record, item, index, e){
alert('help');
}
});
我的問題是在initLogoutButton函數中。 我需要檢索從ajax請求獲得的用戶的唯一實例(總是只有一個實例)。 我可以在js控制台中看到請求,一切都很好,但是我無法使用此數據設置變量或數組!
另外, store.count()函數返回0 。
如果使用代理將數據加載到存儲中,則應注意該請求是異步的! 您需要在商店加載數據后設置按鈕文本。
store.load({
scope : this,
callback: function(records, operation, success) {
// check for success and set the value of button
}
});
加載存儲后,將調用回調函數,然后設置按鈕值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.