PDA

View Full Version : Intercepting and modifing data loaded to store



sergiob
16 Nov 2011, 2:23 AM
I want to intercept JSON data loaded into the store and modify the data before processing it, what is the correct method of doing it?

mitchellsimoens
16 Nov 2011, 1:11 PM
In the Reader that you use... look at getResponseData. I would create an extension of the Json reader and use that method to change the response.

sergiob
17 Nov 2011, 12:41 AM
I'm trying to deploy all the components in app directory by using MVC pattern, how this way to declere the store to use modified Reader? (I know how to instatiate the store and change the reader, but how to do it decalratively in JSON ?)

mitchellsimoens
17 Nov 2011, 6:22 AM
I would just do this:


Ext.define('ReaderName', {
extend: 'Ext.data.reader.Json',
alias : 'reader.readertype',

getResponseData: function(response) {
var json = Ext.decode(response.responseText);

//do your changes here

return json;
}
});

basememara
16 Jan 2012, 7:28 PM
I tried this, but getResponseData never fires.

So I tried overriding readRecords, but I get this error:



Uncaught TypeError: Cannot read property 'length' of undefined
ext-all-debug-w-comments.js: 69467


Was anybody able to get this working? I needed to intercept and modify the data before loading it up into the model (or modify the model after if I can still access the raw data).

basememara
3 Feb 2012, 8:08 AM
There is further discussion on this if you are still having trouble:
http://www.sencha.com/forum/showthread.php?178300-Override-getResponseData-on-reader-does-not-work