2011-02-03 38 views
1

在extjs組合框中,我有這樣的要求:當用戶從組合中選擇一個選項時,捕獲它,下一次加載頁面並組合啓動時,將值(值和顯示值)設置爲用戶最後選擇。 我可以通過Combo.selectedIndex得到用戶選擇的索引,但是當下次加載頁面時我們如何設置這個索引?extjs組合:下次如何將用戶選擇的值設置爲默認選定值?

或者還有其他解決方案嗎?

回答

1

這是非常非常粗糙,但我會做到這一點:

var comboStore = new Ext.data.Store({ 
    ... 
    autoLoad: false, 
    ... 
}); 

var combo = new Ext.form.ComboBox({ 
    ... 
    store: comboStore, 
    ... 
    listeners: { 
     select: function() { 
      ...use getValue() and save here... 
     } 
    } 
}); 

comboStore.on("load",function() { 
    ...load value here... 
    combo.setValue(loaded value); 
},this,{single: true}); 

comboStore.reload(); 
+0

能否請您解釋一下爲什麼這樣做:單:真 – Victor 2011-02-03 16:57:11