开发者

How to get dispayfield in extjs combo?

开发者 https://www.devze.com 2023-02-24 23:16 出处:网络
In extjs combobox, we have valueField, displayField. There is one getValue(). But there开发者_如何转开发 is no getDisaplay(). So how to capture the name of the dispay field?What about getRawValue meth

In extjs combobox, we have valueField, displayField. There is one getValue(). But there开发者_如何转开发 is no getDisaplay(). So how to capture the name of the dispay field?


What about getRawValue method?

Ext.getCmp('combo').getRawValue();


Use the value to get the record out of the store, and get the display value from there.

Abstractly, you can use this code, but you might substitute some of the variables for known values to make it more readable:

getComboDisplay = function(combo) {
    var value = combo.getValue();
    var valueField = combo.valueField;
    var record;
    combo.getStore().each(function(r){
        if(r.data[valueField] == value){
            record = r;
            return false;
        }
    });

    return record ? record.get(combo.displayField) : null;
}


an easy solution that worket for me :

comboselect: function (combo,record) {
    alert(combo.rawValue);
}

hope that help you


In ExtJS 4 there is a built-in findRecord() method that does the searching that BigSean suggested above, so you don't have to write all that code:


Ext.override(Ext.form.field.ComboBox, {
    getDisplayedValue: function() {     // getDisplayValue() already exists but is a private method
        var me = this,
            value = me.value,
            record = null;
        if(value) {
            record = me.getStore().findRecord(me.valueField, value);
        }
        if(record) {
            return record.get(me.displayField);
        }
        return null;
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消