2013-07-08 43 views
0

我有一個組合框獲得價值,我想通過alert(combo.store.data[0].id);從服務器獲取第一條記錄的ID,但它不工作ExtJS的組合 - 從商店的一個AfterRender功能

這裏是我的代碼

 xtype: 'combo', 
     value: '0', 
     triggerAction: 'all', 
     forceSelection: true, 
     editable:  false, 
     allowBlank: false, 
     fieldLabel:  'example', 
     mode: 'remote', 

     displayField:'name', 
     valueField: 'id', 

     store: Ext.create('Ext.data.Store', { 
     ...... 
     ,listeners: { 
       'afterrender': function(combo){   
        alert(combo.store.data[0].id); 
       } 
     } 

如何我可以這樣做,謝謝。

回答

2

可能你錯過了一些東西。

combo.store.getAt(0).data.id 
0

試試這個。

組合框裏面聽衆 「AfterRender階段」:

var getState = combo.getState(), //get current combobox state 
    comboState = parseFloat(getState.value) - 1, 
    comboStore = combo.store; 

comboStore.on("load", function(s,rs) { 
    comboStore.each(function(record, key) { 
     if(key == comboState){ 
      //console.log(record); 
      alert(record.data.id); 
     } 
    }); 
});