I started another try and endet up with the scenario, that I am able to load the first layer of my xml. I have one associated model, which is not loaded at all. What am I doing wrong?
This is my current XML testfile:
Code:
<Sections>
<Section>
<ComponentID>1</ComponentID>
<ParentID>0</ParentID>
<Text lang="en-us">
<ShortText>Some Text</ShortText>
<LongText/>
</Text>
<leaf>true</leaf>
<Item>
<InternalNumber>00001</InternalNumber>
<ExternalNumber>1</ExternalNumber>
<Text lang="en-us">
<ShortText>Another Text</ShortText>
<LongText/>
</Text>
<Comment/>
</Item>
<Item>
<InternalNumber>00002</InternalNumber>
<ExternalNumber>1</ExternalNumber>
<Text lang="en-us">
<ShortText>Another Text 2</ShortText>
<LongText/>
</Text>
<Comment/>
</Item>
</Section>
<Section>
<ComponentID>2</ComponentID>
<ParentID>0</ParentID>
<Text lang="en-us">
<ShortText>Example Text 1</ShortText>
<LongText/>
</Text>
<leaf>true</leaf>
<Section>
<ComponentID>3</ComponentID>
<ParentID>2</ParentID>
<Text lang="en-us">
<ShortText>Example Text 2</ShortText>
<LongText/>
</Text>
<leaf>false</leaf>
</Section>
</Section>
</Sections>
This is my model definition for the sections:
Code:
Ext.define('TOC.model.section', {
extend: 'Ext.data.Model',
uses: [
'TOC.model.item'
],
idProperty: 'component_id',
hasMany: {
associationKey: 'Items',
model: 'TOC.model.item',
primaryKey: 'internal_number',
name: 'items'
},
fields: [
{
name: 'component_id',
mapping: 'ComponentID'
},
{
name: 'short_text',
mapping: 'Text>ShortText'
}
]
});
This is the definition for the items:
Code:
Ext.define('TOC.model.item', {
extend: 'Ext.data.Model',
idProperty: 'internal_number',
fields: [
{
name: 'internal_number',
mapping: 'InternalNumber'
},
{
name: 'external_number',
mapping: 'ExternalNumber'
},
{
name: 'short_text',
mapping: 'Text>ShortText'
},
{
name: 'section_id',
mapping: 'ExternalNumber'
}
]
});
And this is the store:
Code:
Ext.define('TOC.store.sections', {
extend: 'Ext.data.TreeStore',
requires: [
'TOC.model.section'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'Sections',
model: 'TOC.model.section',
proxy: {
type: 'ajax',
url: 'data/demo.xml',
reader: {
type: 'xml',
root: 'Sections',
record: 'Section'
}
},
listeners: {
load: {
fn: me.onXmltreestoreLoad,
scope: me
}
}
}, cfg)]);
},
onXmltreestoreLoad: function(treestore, node, records, successful, options) {
var rec = treestore.getNodeById(1);
console.log(rec.data);
item = rec.items();
console.log(item.count());
}
});
This code is mostly generated by Sencha Architect.
I am able to get the first layer (section) from the XML... but not the items. Another problem is, that the tree does not understand the nesting of sections... The rules for this XML are:
Sections CAN haveMany Sections
Sections CAN haveMany Items
Someone with an idea?
Thanks!
Richard