简体   繁体   English

extjs combo:下次如何将用户选择的值设置为默认选择的值?

[英]extjs combo:How to set user selected value as the default selected value next time?

In extjs combo box, I have this requirement: When the user selects an option from the combo, capture it, and next time page is loaded and combo is init-ed, set the value(both value and displayvalue) to the user's last selection. 在extjs组合框中,我有以下要求:当用户从组合中选择一个选项时,将其捕获,并在下次加载页面并初始化组合时,将值(值和displayvalue)设置为用户的最后选择。 I can get the user selected index by : Combo.selectedIndex , but how do we set this index back when the page loads next time? 我可以通过Combo.selectedIndex获取用户选择的索引,但是当页面下次加载时如何设置该索引呢?

Or is there another solution? 还是有其他解决方案?

This is very very rough but the way I would do it: 这非常非常粗糙,但是我会这样做:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM