2012-01-15 165 views
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"], 

] 

回答

1

我看到您在使用內線得到網格參考.getCmp - 這意味着您對組件的id進行了硬編碼。這不是一個好主意,你最好嘗試使用itemId。它可能導致一些奇怪的錯誤,也許這是你不能工作的原因。嘗試將id更改爲itemId。

+0

我最終摧毀了設計器生成的代碼,它實際上並沒有準備好用於websockets,但現在我的代碼已經可以解決您的問題了。 – BAR 2012-01-18 05:48:33