View Full Version : Reading JSON returned in store

26 Feb 2011, 12:59 PM
I have a JsonStore as follows:

var supplierCount = new Ext.data.JsonStore({
url: 'supplier/countSuppliersByWords/' + $encodedWordsused,
storeId: 'countStore',
root: 'count',
fields: [{name: 'count'}],
listeners: {
load: countLoaded

When I look at the http response I am getting valid JSON back as expected:

{"success" : "true" , "count":"24"}

I want to simply read the value of count. As a test I'm trying to display the count in an alert

function countLoaded(supplierCount) {
var count = xxxxx;
Ext.MessageBox.alert('Count is ' + count);

I've read the samples, the API, searched the forums and spent serious time on this so now I'm asking for help. What's the syntax for replacing xxxx with the the value of count?


26 Feb 2011, 3:09 PM
That's not valid data for a JsonStore (the 'root' must be an array).

But why are you even using a store? A simple request would fit better:

url: 'supplier/countSuppliersByWords/' + $encodedWordsused,
success: function(response){
var data = Ext.decode(response.responseText);

27 Feb 2011, 5:14 AM
Thanks for timely reply. Obvious when pointed out