PDA

View Full Version : Problem loading nested data in a store



MikeB
5 Dec 2011, 10:56 AM
I've seen several threads here and have gone over the docs on this so I'm probably missing something obvious, so I'm hoping someone here will be able to see what I'm missing.

I have a JSON object being read in which contains some nested data:

{success: true, total: 1, records: [{
id: 1,
"RegimenName": "cisplatin vinorelbine",
"cycleLength": "28 days",
"ELevel" : "High",
"FNRisk": "7%",
"Ref": "Winton T, Livingston R, Johnson D, et al. Vinorelbine plus cisplatin vs. observation in resected non-small-lung cancer. N Engl J Med 2005;352:2589-2597.",
"RefURI": "http://www.ncbi.nlm.nih.gov/pubmed/15972865",
"PreMHInstructions": "Prior to cisplatin days 1 & 8",
"PreMHMeds" : [
{ "dose": "NS 1000 ml over 1-2 hours" },
{ "dose": "Aprepitant 125 mg PO" },
{ "dose": "Dexamethasone 12 mg PO/IV" },
{ "dose": "Ondansetron 24 mg PO or 8mg IV" }
],
"Meds": [
{ "drug" : "Cisplatin", "RDose" : "80 mg/m2", "pctDose" : "100%", "reason" : " ", "PatDose" : "", "Route" : "IVPB", "AdminDay" : "Day 1", "fluidVol" : "500 ml NS", "InfusTime" : "1 hour"},
{ "drug" : "Etoposide", "RDose" : "80 mg/m2", "pctDose" : "100%", "reason" : "&nbsp;", "PatDose" : "", "Route" : "IVPB", "AdminDay" : "Day 1-3", "fluidVol" : "less than 200mg 500 ml NS<br />greater than 200mg 1000 ml NS<br />", "InfusTime" : "1 hour"},
{ "drug" : "4", "RDose" : "&nbsp;", "pctDose" : "&nbsp;", "reason" : "&nbsp;", "Route" : "&nbsp;", "AdminDay" : "&nbsp;", "fluidVol" : "&nbsp;", "InfusTime" : "&nbsp;"}

],
"PostMHInstructions": "None at this time...",
"PostMHMeds" : [
{ "dose" : "NS 1000 ml over 1-2 hours after Cisplatin on Day 1" },
{ "dose" : "Aprepitant 80 mg PO q daily days 2, 3" },
{ "dose" : "Dexamethasone 8 mg PO q daily days 2-4" },
{ "dose" : "Prochlorperazine 10mg PO q6 hrs prn nausea/vomiting" }
]
}]}

Note that I've got nested data for "PreMHMeds", "Meds" and "PostMHMeds".

So I built up the Model(s) for this:
Ext.define('COMS.model.MHMed', {
extend: 'Ext.data.Model',
fields: [
{ name : 'dose', type : 'string' } // raw data
],
belongsTo : 'CTOS'
});

Ext.define('COMS.model.Med', {
extend: 'Ext.data.Model',
fields: [
{ name : 'drug', type : 'string' },
{ name : 'RDose', type : 'string' },
{ name : 'pctDose', type : 'string' },
{ name : 'reason', type : 'string' },
{ name : 'PatDose', type : 'string' },
{ name : 'Route', type : 'string' },
{ name : 'AdminDay', type : 'string' },
{ name : 'fluidVol', type : 'string' },
{ name : 'InfusTime', type : 'string' }
],
belongsTo : 'CTOS'
});



Ext.define('COMS.model.CTOS', {
extend: 'Ext.data.Model',
fields: [
'id',
'RegimenName',
'cycleLength',
'ELevel',
'FNRisk',
'Ref',
'RefURI',
'PreMHInstructions',
'PostMHInstructions'
],
hasMany : [
{ model : 'MHMed', name : 'PreMHMeds' },
{ model : 'Med', name : 'Meds' },
{ model : 'MHMed', name : 'PostMHMeds' }
]
});

And a data store:
Ext.define('COMS.store.CTOS', {
extend : 'Ext.data.Store',
model : 'COMS.model.CTOS',
proxy: {
type: 'rest',
url : 'app/data1/CTOS.js',
reader: {
type: 'json',
root : 'records'
}
}
});

And finally in my controller (this is only a snippet of the complete code):
theStore.load({
callback : function() {
var st = theStore;
var ct = st.first();
debugger;
}
});

Now when I run this code I can see on the Firebug console that the proper JSON object is coming in but when I break in the middle of the store callback function above the only data which comes back is:


id : 1
cycleLength : "28 days"
RegimenName : "cisplatin vinorelbine"
RefURI : "http://www.ncbi.nlm.nih.gov/pubmed/15972865"
Ref : "Winton T, Livingston R,...Med 2005;352:2589-2597."
PreMHInstructions : "Prior to cisplatin days 1 & 8"
PostMHInstructions : ""
FNRisk : "7%"
ELevel : "High"

Note that none of the nested records get returned at all...

So anyone see anything like this before? Am I missing something so obvious that I should be ashamed and start looking for a seeing eye dog ;)

TIA for any help
MikeB

Luc
14 Feb 2012, 2:25 PM
Hi,

Perhaps it is an issue that you leave out the COMS.model. prefix for the Model class names in the association configurations.

E.g. try to use COMS.model.CTOS instead of CTOS in the belongs to config.

Like so:



Ext.define('COMS.model.Med', {
extend: 'Ext.data.Model',
fields: [
{ name : 'drug', type : 'string' },
{ name : 'RDose', type : 'string' },
{ name : 'pctDose', type : 'string' },
{ name : 'reason', type : 'string' },
{ name : 'PatDose', type : 'string' },
{ name : 'Route', type : 'string' },
{ name : 'AdminDay', type : 'string' },
{ name : 'fluidVol', type : 'string' },
{ name : 'InfusTime', type : 'string' }
],
belongsTo : 'COMS.model.CTOS'
});





Does that make any difference?

MikeB
14 Feb 2012, 3:49 PM
Thanks Luc, I actually found the answer myself (after a bunch of searching, and I probably should have marked this thread as answered, but I'd forgotten I'd opened it! :D).

The problem WAS in the way I was configuring my Model (first time at attempting nested models with 4.x)


Hi,

Perhaps it is an issue that you leave out the COMS.model. prefix for the Model class names in the association configurations.

Does that make any difference?