PDA

View Full Version : Variable number of fields inside a model



kortovos
27 Sep 2010, 3:37 AM
I am working with complex data (in the form of XML) and I have a question.
How do you work with a variable number of fields inside a model. For instance, below is the data about 2 persons and their cars. But the number of cars is not set/constant. How do you define this in a model, and how do you access the data from the different cars?



<carlist>
<person>
<name>james</name>
<cars>
<car>
<model>Model1</model>
<type>Type1</type>
<licenseplate>AAA-001</licenseplate>
</car>
<car>
<model>Model2</model>
<type>Type2</type>
<licenseplate>BBB-001</licenseplate>
</car>
</cars>
</person>
<person>
<name>Ellen</name>
<cars>
<car>
<model>Model1</model>
<type>Type2</type>
<licenseplate>CCC-001</licenseplate>
</car>
</cars>
</person>
</carlist>

evant
27 Sep 2010, 4:05 AM
If you think about it, the cars belong in a separate store. The fields are totally different, so it makes it an 1-N association.

kortovos
27 Sep 2010, 4:14 AM
If you put the cars into a seperate store, how do you read the data? In the example below I get the data from post 1. How do you seperate them into different stores?


carStore = new Ext.data.Store({
model: 'carlist',
proxy: {
type:'ajax',
url: 'proxytest.php',
extraParams:{action: 'askcarlist',
question: 'carlist'
},
reader: {
type: 'xml',
record: 'person'
}
}
}