PDA

View Full Version : Setting Reader for JsonStore when using Designer



ampeer
20 Jul 2010, 7:01 AM
I have tried searching the forums for an answer to this, apologies if an answer already exists.

I want to be able to set the 'reader' for a JsonStore built within Designer, in order to set the metaData for the store dynamically during the JSON request. My metadata takes effect when I manually write Ext code, but I cannot figure out how to enable the reader from within Designer. Since the JsonStore creates a separate .js file during export from Designer, do I need to instead extend my JsonStore to set the reader property? Something else I'm missing?

There really isn't much in the way of relevant code, besides the JSON response my server is sending to the UI. Everything else is being created automatically by Designer.


{"metaData":{"idProperty":"id","root":"data","totalProperty":"total","successProperty":"success","fields":[{"name":"id","mapping":"id"},{"name":"name","mapping":"name"}]},"data":[{"id":1,"name":"Invoice 1"},{"id":2,"name":"Invoice 2"},{"id":3,"name":"Invoice 3"},{"id":4,"name":"Invoice 4"}],"success":true,"total":4}Thanks for any help.

jarrednicholls
20 Jul 2010, 10:05 AM
Hi ampeer,

You're on the right track. To be honest, you do not need to change anything about the files (JS classes) that are exported with the project. All you would do is supply a "reader" configuration when you go to instantiate your JsonStore...since it would be during the "use" of that class where your dynamic logic takes place. In other words, you wouldn't dynamically create a sub-class and instantiate the sub-class...sounds like too much work to me and not buying you anything :-)

So for example, if your store is named MyStore, you would just do something like this:



var store = new MyStore({
reader: new Ext.data.JsonReader({
// configuration goes here
})
});


Hope that helps!