Eraesr
3 Apr 2012, 6:21 AM
Hi,
I've got some trouble mapping some attribute data in XML elements I'm loading into my store. I found this thread (http://www.sencha.com/forum/showthread.php?191330-XML-mapping-for-attribute-always-returns-empty) which kind of describes the same problem, but I am looking for mapping an attribute from a child element.
So my XML looks like this:
<entries>
<entry>
<id name="capNews" />
<description>Caption for news section</description>
<value>News</value>
</entry>
</entries>
The model looks like this:
Ext.define('MyApp.model.nomenclature', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'name', mapping: 'id@name', type: 'string' },
{ name: 'value', type: 'string' }
]
}
});
The store/reader/proxy is set up as follows:
var reader = new Ext.data.XmlReader({ record: 'entry' });
var proxy = Ext.create('Ext.data.proxy.Ajax', {
url: wordsurl,
model: 'TSW.model.nomenclature',
reader: reader
});
var store = storeManager.getNomenclatureStore();
store.setProxy(proxy);
store.load(....)
Now the value field is loaded properly into the models, but the name field turns up as null. I've tried various mappings like 'id[name]', '@name', 'id/name' but so far I haven't been able to get this to work. Does anyone know what I'm doing wrong?
Oh, to test the contents of the store I'm doing this:
for (var i = 0; i < store.getCount(); i++) {
console.log(store.getAt(i).get('name') + ' => ' + store.getAt(i).get('value'));
}
I've got some trouble mapping some attribute data in XML elements I'm loading into my store. I found this thread (http://www.sencha.com/forum/showthread.php?191330-XML-mapping-for-attribute-always-returns-empty) which kind of describes the same problem, but I am looking for mapping an attribute from a child element.
So my XML looks like this:
<entries>
<entry>
<id name="capNews" />
<description>Caption for news section</description>
<value>News</value>
</entry>
</entries>
The model looks like this:
Ext.define('MyApp.model.nomenclature', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'name', mapping: 'id@name', type: 'string' },
{ name: 'value', type: 'string' }
]
}
});
The store/reader/proxy is set up as follows:
var reader = new Ext.data.XmlReader({ record: 'entry' });
var proxy = Ext.create('Ext.data.proxy.Ajax', {
url: wordsurl,
model: 'TSW.model.nomenclature',
reader: reader
});
var store = storeManager.getNomenclatureStore();
store.setProxy(proxy);
store.load(....)
Now the value field is loaded properly into the models, but the name field turns up as null. I've tried various mappings like 'id[name]', '@name', 'id/name' but so far I haven't been able to get this to work. Does anyone know what I'm doing wrong?
Oh, to test the contents of the store I'm doing this:
for (var i = 0; i < store.getCount(); i++) {
console.log(store.getAt(i).get('name') + ' => ' + store.getAt(i).get('value'));
}