问题
I've recently taken a dive into ExtJS by inheriting a web app written in 3.4. I've managed to create a store attached to a grid with no problem and have been able to bring up a PanelForm with data loaded from a call to a php page.
I have another json store defined which doesn't get populated when I call its load procedure and I'm wondering what I am missing.
The definition of the store is below:
var ImgStore = new Ext.data.JsonStore({
totalProperty: 'total'
,root: 'data'
,url : 'json/getProductImage/'
,fields : [{
name : 'img'
},{
name : 'extn'
}]
});
My code to load the data is:
ImgStore.load({callback: function() {}
,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.
回答1:
Your store needs a model. The model needs to reflect the attributes that are then being returned in your JSON feed. Only then will the data show up in your store.
回答2:
Everything looks fine, except for the url config aren't u missing the name of the file ? 'json/getProductImage/myfile.json'?
How are you validating store is not loaded by binding it to a grid? Because if so, store could be loading but not configuring grid properly might make u think store is not loaded, try console.log(store.getTotalCount())
来源:https://stackoverflow.com/questions/25572954/extjs-json-store-not-populating