PDA

View Full Version : Read multiple lists with Json



gp40
25 Jan 2011, 2:30 PM
I have a scenario where I need to read multiple lists for picklist values. I've tried multiple hasMany entries but it doesn't appear I can have more than one hasMany entries in a model. Simple example below...is it possible to create a model and read the structure below? /Greg




{
"field1":"field1_value",
"field2":"field2_value",
"product": [
{ "product": "MTC", "quantity": "5" },
{ "product": "NTC", "quantity": "15" },
{ "product": "OTC", "quantity": "25" },
{ "product": "XTC", "quantity": "35" }
],
"status": [
{ "sn": "A1", "ln": "Won" },
{ "sn": "A2", "ln": "Close" },
{ "sn": "A3", "ln": "Lost" }
]
}

gp40
28 Jan 2011, 9:17 AM
I'm still struggling with the best way to do this. A little more information....I'm reading the details of a CRM Opportunity. The url returns the detail of the opportunity and the valid picklist values for the updateable fields of the opportunity. I was hoping to use multiple hasMany references in my Detail model but it looks like only one is supported. I did find this thread but I'm unable to get the suggested workaround to work (http://www.sencha.com/forum/showthread.php?115383-Can-t-have-more-than-1-hasMany-association). Is there a fix for this or is there a better way to do this verses making multiple server calls.

Thanks in advance!!! /Greg

gp40
28 Jan 2011, 10:29 AM
I found this post (http://www.sencha.com/forum/showthread.php?113868-Hint-Models-with-hasMany-in-Lists&highlight=hasMany) and the lights came on. Thanks!!!! /Greg




Ext.regModel ('Colors', {
fields: [ {name: 'color', type: 'string'}],
belongsTo: 'Parent'
});
Ext.regModel ('Pets', {
fields: [ {name: 'type', type: 'string'}],
belongsTo: 'Parent'
});
Ext.regModel ('Parent', {
fields: [
{ name: 'first', type: 'string'},
{ name: 'last', type: 'string' },
{ name: 'colors', type: 'array'},
{ name: 'pets', type: 'array'}
],
associations: [
{ type: 'hasMany', model: 'Colors', name: 'colors' },
{ type: 'hasMany', model: 'Pets', name: 'pets' }
]
});