extJS 组合框。动态数据加载

发布于 2025-01-01 13:22:32 字数 1350 浏览 1 评论 0原文

我编写了以下带有动态数据上传的组合框的实现。

代码

Loyalty.tools.DictionaryComboBox = Ext.extend(Ext.form.ComboBox,

 {
    defaultConfig:{

        defaults:{
            labelWidth:150
        },
        displayField:'value',
        valueField:'key',
        forceSelection:true,
        mode:'local',
        typeAhead: true,
        triggerAction: 'all',
        selectOnFocus:true
    },

    constructor:function (config) {
        Ext.apply(config, this.defaultConfig);
        config['store'] = new Ext.data.Store({
            fields:['key', 'value', 'description'],
            proxy:{
                type:'ajax',
                url:config.dictionaryPath + '/' + config.dictionaryName
            }
        });
        Loyalty.tools.DictionaryComboBox.superclass.constructor.call(this, config);
    }

}

 );

,我按以下方式使用它

            new Loyalty.tools.DictionaryComboBox({
                fieldLabel: Loyalty.messages['company.grid.filter.forma'],
                dictionaryPath: config.dictionaryPath,
                dictionaryName: 'forma',
                name: 'forma',
                id:'forma',
                allowBlank:true,
                labelWidth:config.labelWidth
            }),

,但有两个问题 1)如何在加载组合框时获取列表数据(而不是第一次单击时) 2)如果我在组合框中输入一个键,以便它立即显示所需的值?

I wrote the following implementation of combo box with dynamic data upload.

Code

Loyalty.tools.DictionaryComboBox = Ext.extend(Ext.form.ComboBox,

 {
    defaultConfig:{

        defaults:{
            labelWidth:150
        },
        displayField:'value',
        valueField:'key',
        forceSelection:true,
        mode:'local',
        typeAhead: true,
        triggerAction: 'all',
        selectOnFocus:true
    },

    constructor:function (config) {
        Ext.apply(config, this.defaultConfig);
        config['store'] = new Ext.data.Store({
            fields:['key', 'value', 'description'],
            proxy:{
                type:'ajax',
                url:config.dictionaryPath + '/' + config.dictionaryName
            }
        });
        Loyalty.tools.DictionaryComboBox.superclass.constructor.call(this, config);
    }

}

 );

and I use it the following way

            new Loyalty.tools.DictionaryComboBox({
                fieldLabel: Loyalty.messages['company.grid.filter.forma'],
                dictionaryPath: config.dictionaryPath,
                dictionaryName: 'forma',
                name: 'forma',
                id:'forma',
                allowBlank:true,
                labelWidth:config.labelWidth
            }),

I have the two problems
1) How can I get the list data when combo box is loading( rather than on the first click)
2) and if I'm putting a key in the combo box so that it immediately display the desired value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青瓷清茶倾城歌 2025-01-08 13:22:32

1)您如何加载商店。我认为您需要添加 autoLoad: true 像这样

fields:['key', 'value', 'description'],
autoLoad: true,

2) 您是否询问我如何选择组合框

var mycombo = Ext.getCmp('mycombo');
mycombo.setValue(id);

1) how are you loading the store. I think you need to add autoLoad: true like so

fields:['key', 'value', 'description'],
autoLoad: true,

2) are you asking how do i select the combo box

var mycombo = Ext.getCmp('mycombo');
mycombo.setValue(id);
寄风 2025-01-08 13:22:32

我决定了我的问题。不幸的是我不得不使用不“正确”的方法

Loyalty.tools.DictionaryComboBox = Ext.extend(Ext.form.ComboBox,
    {
        defaultConfig:{

            defaults:{
                labelWidth:150
            },
            displayField:'value',
            valueField:'key',
            forceSelection:true,
            queryMode: 'local',
            typeAhead: true,
            triggerAction: 'all',
            selectOnFocus:true
        },

        constructor:function (config) {
            Ext.apply(config, this.defaultConfig);
            var isStoreProvided = (config['store'] == undefined);
            if (isStoreProvided) {
                var el = this;


   config['store'] = new Ext.data.Store({
                fields:['key', 'value', 'description'],
                autoLoad:true,
                proxy:{
                    type:'ajax',
                    url:config.dictionaryPath + '/' + config.dictionaryName
                },
                listeners: {
                    'load': function() {
                        if (config['initialValue'] != undefined) {
                            el.setValue(config['initialValue']);
                            config['initialValue'] = undefined;
                        }
                    }
                }
            });
        }
        Loyalty.tools.DictionaryComboBox.superclass.constructor.call(this, config);
    }

}

);

i decided my problem. Unfortunately I had to use not "right" metod

Loyalty.tools.DictionaryComboBox = Ext.extend(Ext.form.ComboBox,
    {
        defaultConfig:{

            defaults:{
                labelWidth:150
            },
            displayField:'value',
            valueField:'key',
            forceSelection:true,
            queryMode: 'local',
            typeAhead: true,
            triggerAction: 'all',
            selectOnFocus:true
        },

        constructor:function (config) {
            Ext.apply(config, this.defaultConfig);
            var isStoreProvided = (config['store'] == undefined);
            if (isStoreProvided) {
                var el = this;


   config['store'] = new Ext.data.Store({
                fields:['key', 'value', 'description'],
                autoLoad:true,
                proxy:{
                    type:'ajax',
                    url:config.dictionaryPath + '/' + config.dictionaryName
                },
                listeners: {
                    'load': function() {
                        if (config['initialValue'] != undefined) {
                            el.setValue(config['initialValue']);
                            config['initialValue'] = undefined;
                        }
                    }
                }
            });
        }
        Loyalty.tools.DictionaryComboBox.superclass.constructor.call(this, config);
    }

}

);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文