1
我正在使用設計人員,我的目標是通過單擊newBtn更新迄今爲止已啓動的存儲記錄。我試圖在調用它的函數之外執行它。extjs更改存儲數據時更新
如果我嘗試點擊它的按鈕。
./application.js
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
name: 'MyApp',
stores: [
'MyArrayStore'
],
launch: function() {
Ext.QuickTips.init();
var cmp1 = Ext.create('MyApp.view.TradeGrid', {
renderTo: Ext.getBody()
});
cmp1.show();
//PROBLEM HERE
// This actually does something but when maxIndex is printed to the console it = 0
// Meaning that no data has been loaded to grid
// Am I wrong thinking it should? As the other file loads two data cells right away
cmp1.addRecord([]);
//PROBLEM HERE
./TradeGrid.js
Ext.define('MyApp.view.TradeGrid', {
extend: 'MyApp.view.ui.TradeGrid',
initComponent: function() {
var me = this;
me.callParent(arguments);
var button = me.down('button[text=newBtn]');
button.on('click', me.onSubmitBtnClick, me);
},
addRecord: function(myRecordArray) {
var grid = Ext.getCmp("TradeGrid"); //defined by -> Property: id
var store = grid.getStore();
var maxIndex = store.getCount();
console.log(maxIndex); //maxIndex PRINT to CONSOLE
var res = store.insert(maxIndex, [["ll", "kk", "00"]]);
console.log(this);
},
onSubmitBtnClick: function() {
this.addRecord([]);
}
});
}
});
前兩個數據加載到網格
[
["Ace Supplies", "Emma Knauer", "555-3529"],
["Best Goods", "Joseph Kahn", "555-8797"],
]
我最終摧毀了設計器生成的代碼,它實際上並沒有準備好用於websockets,但現在我的代碼已經可以解決您的問題了。 – BAR 2012-01-18 05:48:33