如何从组合框选择的记录中获取所有值?

pw136qt2  于 2022-09-26  发布在  其他
关注(0)|答案(2)|浏览(208)

我有一个组合框,它从DB返回10个值;

Ext.define('Iso3Combo', {
    extend:'',
    xtype:'iso3combo',

    requires: [
        'Ext.data.proxy.Ajax',
        'Ext.data.reader.Json'
    ],

    name: iso3
    fieldLabel: iso3,
    displayField:'iso3', // takes from DB 
    valueField:'id', // takes from DB
    store: {
        proxy: {
            type: 'ajax',
            url: ...getUrl() + '/country/list',
            reader: {
                type: 'json',
                rootProperty: 'data'
            }
        },
        autoLoad: true
    },
    queryMode: 'local',
    autoLoad:true,
    bind: '{currRec.iso3}',
    listeners: {
                        fn: function () {
                          console.log('isocombo listeners...');
                        },
                        select: this.getIso3,
                        change: this.getIso3,
                        scope: this
                    }
});

如上所述;combobox显示的内容是e1d1e,并将id作为主键。因此,我无法更改valueField。因此,尝试使用此函数来获取所选组合框记录的其他值;

getIso3: function () {
        var me = this;

        // var rec = me.getSelectedRecords(); //says getSelectedRecords is not a function

        var country = me.down('[name=iso3]').getValue(); // returns 'id'
        // var isoCode = rec.data.iso3; //Couldn't be success to verify if I get correct value..

如何才能从所选组合框记录加载DB的所有值并选择其中一个?

rsaldnfx

rsaldnfx1#

您需要使用combobox.getSelection()或e1d1e。此both方法将返回您选择的记录。或者在select事件中,您将在第二个parameter中获得选定的record,这样您也可以获得iso3值,如record.get('iso3')所示。
这是一个FIDDLE,我用formcombobox创建了一个演示。这将帮助或指导您解决问题。
我正在使用这个**COUNTRY JSON**。

代码段

// The data store containing the list of Country
var country = Ext.create('Ext.data.Store', {
    fields: ['iso3', 'id'],
    proxy: {
        type: 'ajax',
        url: 'countryList.json',
        reader: {
            type: 'json',
            rootProperty: 'countrylist'
        }
    },
    autoLoad: true
});

// Create form  with the combo box, attached to the country data store
Ext.create('Ext.form.Panel', {
    title: 'Country List Example with ComboBox',
    bodyPadding: 10,
    items: [{
        xtype: 'combo',
        fieldLabel: 'Choose Country',
        store: country,
        queryMode: 'local',
        displayField: 'iso3',
        valueField: 'id',
        listeners: {
            select: function (field, record) {
                Ext.Msg.alert('Success', `Selected country <br> iso3 : <b>${record.get('iso3')}</b> <br> id : <b>${record.get('id')}</b>`);
            }
        }
    }],
    renderTo: Ext.getBody(),
    buttons: [{
        text: 'Get Combo Value/Record on button click',
        handler: function () {
            var record = this.up('form').down('combo').getSelectedRecord();
            if (record) {
                Ext.Msg.alert('Success', `Selected country <br> iso3 : <b>${record.get('iso3')}</b> <br> id : <b>${record.get('id')}</b>`)
            } else {
                Ext.Msg.alert('Info', 'Please select contry first.. :)');
            }
        }
    }]
});
xwbd5t1u

xwbd5t1u2#

handler: function () {
   var selectionmodel=this.up().down('multiselect');
    var values=selectionmodel.values;
}

相关问题