PDA

View Full Version : Array Reader reading only the first character of the array elements.



AkshayKalbhor
10 Mar 2014, 1:50 AM
Hello,

I have a comboBox which reads the data through a Rest Webservice, Which returns the data as a array of string as follows:


["COLLEGE","SCHOOL","UNIVERSITY","TRAINING_INSTITUTE","FRANCHISE"]

The store is attached to a combobox.
I have added a reader to my Store which uses the reader in the proxy, but the combo displays the initials of the recieved data.

the code of the store looks as :

var myReader = new Ext.data.reader.Array({ model: 'APP.model.genericmodels.dropdowns.SettingsCombo'
});

Ext.define('APP.store.organization.OrganizationTypeStore',{
extend:'Ext.data.Store',
//fields:['name'],
model: 'APP.model.genericmodels.dropdowns.SettingsCombo',
autoload: true,

proxy : {
type: 'rest',
api : {
read:'/rest/pickListItem/findAllOrganizationTypes',
write:'/rest/organization/create'
},
reader: myReader
}
});



Also attaching the drop down screenshot.48218

here "C" is the initials of the data recieved (here -> College).

Please help me with the missing things.

chramer
10 Mar 2014, 1:55 AM
show us what you have in 'APP.model.genericmodels.dropdowns.SettingsCombo'

AkshayKalbhor
10 Mar 2014, 2:21 AM
Model: SettingsCombo


Ext.define('APP.model.genericmodels.dropdowns.SettingsCombo', {
extend: 'Ext.data.Model',

fields: [
{ name: 'name' }
]
});

chramer
10 Mar 2014, 4:30 AM
http://docs-origin.sencha.com/extjs/4.2.2/#!/api/Ext.data.reader.Array
The expected format for an array reader is: "[ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]".
So in your case, it has to be: [["COLLEGE"],["SCHOOL"],["UNIVERSITY"],["TRAINING_INSTITUTE"],["FRANCHISE"]].

Also I would suggest optimizing your code.
Get rid of the model. You have only one field, so just put it in the 'fields' config of the store.
Also you can remove the reader and use a 'Ext.data.ArrayStore', which is automatically configured with a 'Ext.data.reader.Array'.
So you should get something like this:


Ext.define('APP.store.organization.OrganizationTypeStore', {
extend: 'Ext.data.ArrayStore',
fields:['name'],
autoload: true,

proxy: {
type: 'rest',
api: {
read: '/rest/pickListItem/findAllOrganizationTypes',
write: '/rest/organization/create'
}
}
});

Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Organization Type',
store: Ext.create('APP.store.organization.OrganizationTypeStore'),
queryMode: 'local',
displayField: 'name',
renderTo: Ext.getBody()
});


Good luck ;)

P.S.
Interesting how you got the combo with the initials. I couldn't reproduce that!

AkshayKalbhor
10 Mar 2014, 8:40 PM
I did solve the problem by overriding the "getResponseData" of the reader as i was not allowed to change the format of the data as suggested by "chramer".