I’m trying to use XML TreeStore in Sencha Architect and it fails to load any data from the given XML. While I can access that store as an object, its getCount() returns ‘undefined’ and methods like getNodeById('foobar') result in ‘cannot read property ‘foobar’ of undefined’ which makes me think the mapping doesn’t happen (store is initialised but failed to parse the data / instantiate models).
The same XML with the same model but accessed via a flat store in the same basic setup works fine (e.g. getCount() returns 2 as expected). Tree store with a JSON version of data again works fine as well.
The class for my problematic store by Sencha Architect is:
Ext.define('MyApp.store.DocumentStore', {
extend: 'Ext.data.TreeStore',
requires: [
'MyApp.model.Document'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'TreeDocumentStore',
model: 'MyApp.model.Document',
proxy: {
type: 'ajax',
url: 'DocumentTemplates.xml',
reader: {
type: 'xml',
root: 'Templates',
record: 'Template'
}
}
}, cfg)]);
}
});
The source XML file store refers to is:
<?xml version="1.0" encoding="UTF-8"?>
<Templates>
<Template>
<Id>A253338C-CDFA-4182-9E1C-652EAAB713F8</Id>
<Title>Template 1</Title>
<Children />
</Template>
<Template>
<Id>26D5B83C-7E9E-49E2-B174-F9A6C7BA07A8</Id>
<Title>Template 2</Title>
<Children />
</Template>
</Templates>
In case I have misunderstood the purpose of ‘root’ property I tried different node names for global root and supposed child node roots setting ‘root’ property of the reader to all the possible values, but no luck.
I tried to remove empty from the nodes as well, same effect.
This is not about displaying items from the store in a view yet, I’m only trying to access the data in controller.
P.S. Dummy project with an XML file, tree store and controller accessing that store in onLaunch is here: http://sdrv.ms/RAsj26
Having spent some time with this issue my own answer to a similar question is probably relevant: https://stackoverflow.com/a/12886943/454266
Looks like tree structures for XML sources are not supported properly in the current version of framework, be it TreeStore or association mechanisms.