PDA

View Full Version : Store(json) load, how to get the complete response?



klodoma1
25 May 2012, 2:03 PM
Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json',
root: 'users'
}
},
});


Let's imagine the upper store and the following data being send on load request:


{
"success": true,
"details": "some text",
"users": [
{ "name": "User 1" },
{ "name": "User 2" }
]
}


This store is attached to a grid. The users are passed fine. I need to read also the "details" values out of the response as I need to pass it further to other components.

In Extjs3 this was done on the "load" event of the HttpProxy which was attached to the store, but I couldn't find any solution in Ext4. I found no way to get to the proxy "complete request" except when an exception occurs.

Please advise. Thanks.

chramer
25 May 2012, 2:30 PM
store.load({
success : function(record, operation)
{
//on success:true
console.log(operation.request.scope.reader.rawData.details);
},
failure : function(record, operation)
{
//on success:false
console.log(operation.request.scope.reader.rawData.details);
},
callback : function(record, operation)
{
//always
console.log(operation.request.scope.reader.rawData.details);
}
});

scottmartin
25 May 2012, 3:21 PM
To add to this, please review the section 'Loading Nested Data'
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store

Regards,
Scott.

klodoma1
26 May 2012, 2:14 AM
Thanks all, you helped me to find out something else, which fits better to my needs:


Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url : 'users.json',
reader: {
type: 'json',
root: 'users'
}
},
listeners: {
'load' : function(store, records, success, options){
//the complete response
console.log(store.getProxy().getReader().rawData);
}
}
});