View Full Version : Read special JSON into store

17 May 2013, 5:34 AM

I'm totally stuck at a point for a while now. Maybe I'm just too stupid to understand the idea behind the stores. I have following Json string

{ "1":[0,68,65,75],

And my store looks like this.

Ext.define('MyStore.Adjacencies', {
extend: 'Ext.data.Store',
storeId: 'ThemeAdjacencies',

fields: [
name: 'theme'

proxy: {
type: 'ajax',
url: 'data/Matrix.json',
reader: {
type: 'array',

But unfortunately this only reads the first line of the json. Is there an option to read the complete data?

Thanks for any hints and helps.

17 May 2013, 5:59 AM
take a look at:
(example on top)

most of the time, i return a JSON string like:

"data": [

the important part is, that you specified "theme" as a field inside your model, so the reader will search for this field in the response.

best regards

17 May 2013, 6:04 AM
Hi Tobi,

I already tried changing the reader to JSON. But that just looks for the property 'theme' as intended. Unfortunately I can not change the JSON file. So I really need to read the above given JSON.
The trick is, that it does not have a constant property to read. But that the property ("1", "2",...) is changing.

17 May 2013, 8:34 AM
if you can not change the JSON response, you will need to create a custom reader, which is a bit tricky but possible.

i recommend to extend the json one:

especially take a look at:

extractData: function(root) {
var recordName = this.record,
data = [],
length, i;

if (recordName) {
length = root.length;

if (!length && Ext.isObject(root)) {
length = 1;
root = [root];

for (i = 0; i < length; i++) {
data[i] = root[i][recordName];
} else {
data = root;
return this.callParent([data]);

20 May 2013, 11:22 PM
Hi Tobi,

thanks for the hint. I'll give it a try.