1
votes

I have a object that has some values that i want to display in a combobox that i am adding to a form panel inside a for loop.

this is the contents of the object object but in my combobox i get data as [object Object] here is what i am currently doing

        for(var i = 0; i < data.length ; i++)
{
    console.log('ad');

    var storeStates = new Ext.data.ArrayStore({
        fields: ['optionText'],

        data : [data[i].data.selectOptions.list[i].optionText]
    });

    var cb = new Ext.form.ComboBox({
        fieldLabel:  data[i].data.name,
        hiddenName: 'fieldTypeName',
        id: data[i].data.name.toString(),
        valueField: 'optionText',
        displayField: 'optionText',
        typeAhead: true,
        allowBlank: false,
        mode: 'local',
        selectOnFocus: true,
        triggerAction: 'all',
        emptyText: 'Survey Field Type',
        disabled: this.existingField,
        width: 190,
        store:  storeStates,
        listeners: {
            'select': function (combo, newValue, oldValue) {

            }
        }



    });

    Ext.getCmp('survey-field-form').add(cb);
//Ext.getCmp('survey-field-form').doLayout();


console.log('added');

}

3

3 Answers

0
votes

You need to change your store definition from Ext.data.ArrayStore to Ext.data.Store & data as data[i].data.selectOptions.list

 var storeStates = new Ext.data.Store({
        fields: ['optionText'],
        data : data[i].data.selectOptions.list
    });
0
votes

I think you need to define your store like that to get the correct display:

 var storeStates = new Ext.data.JsonStore({
                    data: data[i].data.selectOptions.list,
                    fields: [{name: "optionText", type: "string"}]
});
0
votes

I solved it by creating a reader and a store and pushing data into the store and then loading the store like this

 // create a Record constructor:
            var rt = Ext.data.Record.create([
                {name: 'optionValue'},
                {name: 'optionText'}
            ]);
            var myStore = new Ext.data.Store({
                // explicitly create reader
                reader: new Ext.data.ArrayReader(
                    {
                        idIndex: 0  // id for each record will be the first element
                    },
                    rt // recordType
                )
            });
            var myData = [];

            for(var j = 0; j < data[i].data.selectOptions.list.length; j++)
            {

                var optionText = data[i].data.selectOptions.list[j].optionText.toString();
                var optionValue = data[i].data.selectOptions.list[j].optionValue.toString();

                myData.push([optionValue, optionText]);

            }

            myStore.loadData(myData);

Hope this helps someone else