PDA

View Full Version : Reading more Data than a Record from JsonReader



aconran
21 Feb 2007, 12:59 PM
Just wondering what is the best way to implement this.....

I am loading a dialog which has some general information and then an array of records for a grid. I use the JsonReader to read the array of records and place them in a datastore for my grid.

Since I've already loaded this general information in my JSON and I'd like to use it even though it's not part of my record.. I was hoping maybe there was an event that I could listen to for the record but this is not the case.

For more clarification a mock-up of my JSON:
{"genInfo1":"some stuff here",
"genInfo2":"more info","myArray":[{"subA":"1","subB":"2"},{"subA":"213","subB":"232"}]}

I want to be able to read genInfo1 and genInfo2 although a define a JsonReader with a root of "myArray" for my Record object.

Make sense?

jack.slocum
21 Feb 2007, 1:35 PM
Here's some useful properties for JsonReader/JSON backed records:

- Every record object has a json property that has the raw JSON used to read the record. You can stick complex types in this if you wanted.

- In your case, there is also a jsonData property on the reader which contains the last read full json data from your request. You can use that to get your 'genInfo1', 'genInfo2'.

var myInfo = reader.jsonData.genInfo1;

Combined with the Store(or HttpProxy) load event, you could snag this data and use it to load other data stores or whatever you want.

aconran
21 Feb 2007, 1:49 PM
Jack -

Thanks, worked perfect! Just to give others a practical example.... Loading this data into 3 form fields when the datastore loads. Now I just have to figure out how I am going to do the data marshalling.

Aaron


ds.on('load', function() {
Ext.fly('disclaimer').dom.value = reader.jsonData.disclaimer;
Ext.fly('spanfrom').dom.value = reader.jsonData.spanfrom;
Ext.fly('spanto').dom.value = reader.jsonData.spanto;
if (!ds.getCount()) {
alert('No records. take appropriate action.');
}
else
{
deleteBtn.enable();
}
});

Belgabor
21 Feb 2007, 2:02 PM
Very nice, I also noticed this option. I just wanted to add that this would be the perfect method to communicate server errors back to the ui. Sounds (and is) somewhat obvious, but I thought it would still be good to post the idea for people searching for exactly that :)

jerry.zhu
21 Feb 2008, 5:40 PM
Thanks, I am just looking for it.

softwareengineer
1 Jun 2010, 12:41 AM
Here's some useful properties for JsonReader/JSON backed records:

- Every record object has a json property that has the raw JSON used to read the record. You can stick complex types in this if you wanted.

- In your case, there is also a jsonData property on the reader which contains the last read full json data from your request. You can use that to get your 'genInfo1', 'genInfo2'.

var myInfo = reader.jsonData.genInfo1;

Combined with the Store(or HttpProxy) load event, you could snag this data and use it to load other data stores or whatever you want.

I am getting below error can any one help me in this.
Ext.data.Api is undefined
chrome://firebug/content/blank.gif Ext.iterate(Ext.data.Api.actions, function(action) { DwrProxy.js line 55

softwareengineer
1 Jun 2010, 12:45 AM
Hello All,
Can any one help me to come out from this.

Ext.data.Api is undefined
chrome://firebug/content/blank.gif Ext.iterate(Ext.data.Api.actions, function(action) {
}

DwrProxy.js line 55

Please help me.