PDA

View Full Version : JsonStore for a single record?



js_coder
11 Aug 2009, 11:25 AM
Is it possible for a JsonStore to only anticipate a single record? I want to handle JSON packets like this one:


{'site': {'attr': 'value', 'attr2': 'value'}}

If not, what do I have to do, client or server side, to smoothly pass a single record into Ext3?

tryanDLS
12 Aug 2009, 6:14 AM
Even if you have only 1 record, JsonStore still expects an array.

js_coder
12 Aug 2009, 6:31 AM
Yea, when I thought about it, it made more sense to just fetch the single record with a standard Ext request rather than using a reader.

rubinsh
27 Apr 2011, 8:35 AM
Can you please post an example of how to fetch a single json record using an Ext request?

Thanks!

friend
27 Apr 2011, 8:47 AM
An Ext.Ajax.request() has no notion of what a 'record' is, it's only concerned with some block of data.

If you're dealing with a Grid/JsonStore, then keep things within the context of a store.

If you just want an Ext.Ajax.request() to pull back a chunk o' JSON:



Ext.Ajax.request({
url: 'someUrl',
method: 'GET',
// params: {
// someParam: 'someValue'
// },
success: function(result, request) {
var json = Ext.decode(result.responseText);
Ext.Msg.alert('Response', 'site.attr == ' + json.site.attr);
},
failure: function(result, request) {
Ext.Msg.alert('Error!', 'Some bad mojo on the server side...');
}
});

rubinsh
28 Apr 2011, 2:57 AM
Thanks!
This was exactly what I needed! :-)