PDA

View Full Version : JSON store not populating



mrh121
28 Aug 2014, 4:37 PM
Hi Forum followers :)

I'm new to ExtJS having inherited an application..

I have a json store defined which doesn't get populated when I call its load procedure and I'm wondering what I am missing.

My store is defined as below:


var ImgStore = new Ext.data.JsonStore({
totalProperty: 'total'
,root: 'data'
,url : 'json/getProductImage/'
,fields : [{
name : 'img'
},{
name : 'extn'
}]
});

I am trying to load the store via:


ImgStore.load({callback: function() {}
,url : 'json/getProductImage/',
params: {'ProductGUID': x}
});


The code behind the URL is fine and the response in Firebug below:


{"success":true,"data":{"img":"iVBORw0KG...ggg==","extn":"png"}}

What I cannot understand is why the response comes back but the Store does not populate. I must be missing something; I just can't see what...

Does the Store have to be bound to another object? What I wanted to do was to read back the base64 encoded string and then show the image on screen (on either a panel, FormPanel or Container; not really sure of the best method really)

Any advice is greatly received.

Simon

slemmon
10 Sep 2014, 4:44 PM
Hi,

The issue you're running into is that in Ext3 the data response in the root needed to be an array [] and in this case it's an object (unless the response contains an id field/value in which case the reader wraps arrayifies the response).

So, three options:
1) Wrap your response as an array even if it's one record
2) Pass back an ID
3) Extend the writer to use different logic in isData
http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.data.DataReader-method-isData

The first option is my favorite, but I'll defer to your judgement. :)