View Full Version : Convert Store with Nested Stores to Plain Old JavaScript Object (or JSON)

20 Nov 2012, 9:50 AM
Although i have achieved the desired functionality i am in search of the recommended best practice.

I have this JSON

description:"Alagi kadenas xronismou, Alagi ladion , zigostathmisi kai alla polla",
{id:"43",name:"kadena xronismou",price:"50",quantity:"1"},
{id:"05",name:"Motul 1L 15/40",price:"12",quantity:"4"}

The Parts Model is correctly associated with SessionDetails Model using the HasMany property.

So when is get the data from the JSON i get a
Store (with 1 sessionDetails record) containing another Store with Part records.

When i call sessionDetailsStore.first().getData() i get only the primary node data
(all fields not the array. Also i used firebug and the Parts array is on a completely different node unrelated with the JSON structure).
The Parts Store is accessible via calling sessionDetails.parts().

Finally i want to convert all data into a POJO in order to use it on a XTemplate.

My solution is this.

var detailsRecord = SessionDetailsStore[0] (The parent Store)
var detailData = detailsRecord.getData();

detailData.parts = new Array();
var partsArr = detailsRecord.parts().getRange();
for(var i=0; i<partsArr.length;i++){
detailData.parts[i] = partsArr[i].getData();

Shouldn't be a way of converting the store to it's primitive data-form using a simple command?

22 Nov 2012, 6:20 AM
You are doing it properly. This isn't normally done as vast majority don't need to.