PDA

View Full Version : How do you parse JSON that has two arrays containing different model types?



orangechicken
2 Aug 2010, 12:52 PM
Assume you have two models "Pivot" (with title and url properties) and "Content" (with title and several more properties). The JSON returns something like `{ pivots: [{ Pivot }, ...], data: { Content }}`. I'm guessing the default JsonStore won't handle this, right?

A related question (that might solve the above with a meta-model): How can I convert children in the data to models of different types? (So, I could have a Page model that had Pivots and a piece of Content)

Thanks,
Dave

orangechicken
3 Aug 2010, 3:22 PM
Galdang this board keeps eating replies. Let's try again.

What I really want is for the JsonStore to look at the 'type' attribute in each returned record and use that for the model. Looks like maybe I could create a custom Ext.data.Reader and override buildExtractors and extractData. Does that sound like the right path?

orangechicken
3 Aug 2010, 3:25 PM
I guess I'd extend Ext.data.JsonReader (overriding those same methods though)