aayush_v20
aayush_v20

Reputation: 203

Add a value in combobox without a store

I am using REST services to communicate with the server and that function returns a HashMap. I need to use this HashMap to populate the combobox. I have made an ajax request for retrieving that HashMap (in a javascript var). Now that I have this HashMap I need to add the 'keys' as options in the combobox.

Is it possible with the help of some insert function without creating a store since my HashMap is itself like a store. How do I accomplish this?

I wanted to do something like this :

for (var field in json) {
    combo.add(field) // Is there any function or a way by which I can do this
}

Upvotes: 1

Views: 1443

Answers (1)

tomgal
tomgal

Reputation: 136

Maybe convert it to array of Ext.data.Records and add use something like below

Ext.getCmp('COMBO_ID').getStore().add([new Ext.data.Record({
    id: 900,
    desc: 'qweqwe' // depends on your combo config
    }
)]);

// complete
var combo = Ext.create('Ext.form.ComboBox', {
    fieldLabel: 'Choose State',
    id: 'mycombo',
    queryMode: 'local',
    displayField: 'name',
    valueField: 'id',
    store: [],
    renderTo: Ext.getBody()
});
combo.getStore().add([[2, 'qweqwe']]);

Upvotes: 2

Related Questions