PDA

View Full Version : Combobox problem with store variables



LionRock
28 Aug 2013, 4:25 AM
Hi,

in grid I can use json like this:

[
{"User":{"id":"1","username":"test1"} ,"Group": {"id":"1","name":"test"}},
{"User":{"id":"2","username":"test2"} ,"Group": {"id":"2","name":"test2"}}
]

and in dataIndex config I can define field like "User.username" or "Group.name" but in Combobox valueField must be like "value" and displayField like "text". I cant use Group.name and Group.id instead. Why?

carol.ext
28 Aug 2013, 8:01 AM
Not sure what you are needing, but this worked for me.


// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: [
{name: 'abbr', mapping: 'state.abbr'},
{name: 'name', mapping: 'state.name'}
],
data : [
{state: {"abbr":"AL", "name":"Alabama"}},
{state: {"abbr":"AK", "name":"Alaska"}},
{state: {"abbr":"AZ", "name":"Arizona"}}
//...
]
});

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
});

LionRock
28 Aug 2013, 9:55 AM
Goshhhh. Thank you very much!!! I didn't know for "mapping" config :/ Im new to extjs and in such a big framework you can miss something easily. Thank you very much again!


Thanks!