PDA

View Full Version : Howto use proxy or reader with custom data



wolfgang18
25 Jun 2013, 4:04 AM
Hi,

My project is based on custom data which is requested and received via a websocket connection. The result data is textual and has to be parsed and transformed to JSON objects in the client. I'd like to feed my model with the JSON-fied results automatically. How can this be achieved via a proxy and/or a reader.
Currently I could not find an adequate solution an use an overridden Ext.store load function to retrieve the data, enhance it and write to the store manually


myStore.add({data: websocketResult.text});
myStore.sync();


Has anybody a smart solution?

Farish
25 Jun 2013, 4:21 AM
One possible solution is to use Ext.Ajax request to fetch your data. then on success, you could parse your data into an array and use the store's loadData method to feed your data into the store. Take a look at the API docs for Ext.Ajax and store.loadData() and you will also find example code on how to put these to use.

wolfgang18
25 Jun 2013, 5:47 AM
I cannot use Ext.ajax, since the interface to the backend is a websocket. At least I don't know how to manage the communication via ajax in this case. I have seen a websocket plugin for ExtJS but I cannot use this for my solution.

Should I override the Ext.data.ArrayReader to feed my proxy (to feed the model)? And how would I do this? I need an entry point (constructor?) in the reader where I could read the data from the socket.

slemmon
26 Jun 2013, 10:02 PM
ExtJS doesn't have a websocket proxy class. For the time being you'll need to find some way to fetch the data from your server (socket.io?).

Once you have the data fetched you can extend a datareader to do the parsing for you. Guess you could parse it into a JSON string and feed that to the JSON reader, but for your use case sounds like it might end up being beneficial to have your own custom reader that just does the work when fed the custom dataset.