Question

This is my model for my combo

Ext.define('ExtJS.myApp.ComboModel', {
    extend: 'Ext.data.Model',
    alias: 'widget.combomodel',
    fields: [
        { name: 'ID', type: 'int' },
        { name: 'title', type: 'string' }
     ]
});

This is comboStore

   this.comboStore = Ext.create('Ext.data.Store', {
        model: 'ExtJS.myApp.ComboModel',
        autoLoad: true,
        scope: this,
        proxy: {
            type: 'ajax',
            scope: this,
            url: 'myApp/GetRecords',
            reader: {
                type: 'json',
                root: 'data'
            }
        }
    });

    this.myComboBox = Ext.create('Ext.form.ComboBox', {
        store: this.comboStore,
        queryMode: 'local',
        displayField: 'title',
        valueField: 'ID'
    });

This is the json object I get for my store:

{"ID":"111","title":"Ext Page 1"}

now when I try to set the value of the combobox like this. this.myComboBox.setValue('111');

the combobox shows "111" instead of "Ext Page 1"

What would I have to do so that the combobox displays displayField while setting valueField. For example. I want to set the value as "Ext Page 1" for the user to see, but When save the value, I actually want to save "111'

Was it helpful?

Solution

try:

this.myComboBox.setValue(111);

instead of:

this.myComboBox.setValue('111');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top