【问题标题】:extjs combo:How to set user selected value as the default selected value next time?extjs combo:下次如何将用户选择的值设置为默认选择值?
【发布时间】:2011-02-03 16:05:08
【问题描述】:

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

    【讨论】:

    • 你能解释一下我们为什么这样做吗:single: true
    • Single 基本上让听者只触发一个。我们这样做是因为我们只想在首次启动时加载一次默认值。
    猜你喜欢
    • 2021-06-28
    • 2014-08-25
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2017-04-28
    • 1970-01-01
    • 2021-08-10
    • 1970-01-01
    相关资源
    最近更新 更多