PDA

View Full Version : Model data with a 1 to 1 relationship



BostonMerlin
18 Aug 2011, 11:44 AM
I'm trying to access the following JSON from my model store. I have no problem accessing the root (Name and Address) but i can't access anything in Financials (NetWorth or Income). I've verified the JSON below is being returned from the server.

I know this has to be super easy but every example i've seen is showing how to access a 1 to many relationship. My model is a 1 to 1. Person->Financials. Right now i don't have any associations setup as i don't know how to setup a 1 to 1 relationship. I've tried associations, i've tried belongsTo, i've tried Financials.NetWorth from inside my itemTPL. Nothing.

Can someone please show me the light? Thanks, John



[{
"PersonName": "John Smith",
"Address": "123 main street",
"Financials":
[{
"NetWorth": "$500,000",
"Income":"$67,000"
}]
}]


I registered my Models.




Ext.regModel('Person', {
fields: [
{name: 'Name', type:'string'},
{name: 'Address', type: 'string'},
],
});

Ext.regModel('Financials',{
fields: [
{name: 'NetWorth', type:'string'},
{name: 'Income', type: 'string'},
],
});








And registered the store







var commStore = new Ext.data.Store({
model: 'Person',
proxy: {
type: 'ajax',
url : 'Business/GetData',
reader: {
type: 'json',
}
},
autoLoad:false,
});





and displaying back in a list




var commList = new Ext.List({
fullscreen: false,
itemTpl : '<div>{PersonName}</div><div>{NetWorth}</div>',
store: commStore,
height:500,
width:"100%",
});






Any help would be much appreciated. Thanks again, John