2012-01-15 4 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グリッドに

[ 
["Ace Supplies", "Emma Knauer", "555-3529"], 
["Best Goods", "Joseph Kahn", "555-8797"], 

] 

答えて

1

をロード

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([]); 
    } 




}); 

     } 
    }); 

最初の二つのデータ.getCmp - コンポーネントのIDをハードコードしたことを意味します。それは本当に良いアイデアではありません、あなたはitemIdを使うことをお勧めします。それはいくつかの奇妙なバグをリードすることができます、多分それはあなたの可能性がありますが動作していない理由です。 idをitemIdに変更してみてください。

+0

私はデザイナーが生成したコードを駄目にしてしまいました。実際にはウェブソケットの準備ができていませんでした。 – BAR

関連する問題