PDA

View Full Version : Advanced XML Store



originalanaya
6 Nov 2009, 2:58 AM
hi guys, i'm trying load a xml like...
items.xml:


<items>
<item id ="0" name="typeBasic" ></item>
<item id ="20" name="typeChildsProp">
<depend id="201" name="ChildProp 1"/>
<depend id="202" name="ChildProp 2"/>
</item>
<item id ="10" name="typeChildsItems">
<item id="101" name="ChildItem 1"/>
<item id="102" name="ChildItem 2"/>
</item>
</items>
but.. how i can load childsnodes?


new Ext.data.XmlStore({
storeId: 'myStore',
url: 'items.xml',
record: 'item',
id:'id',
fields: [
{name:'id' ,mapping:'@id' },
{name:'name' ,mapping:'@name'},
{name:'ItemsChilds',mapping:'item' }, // ChildItemList ?! :s
{name:'depend' ,mapping:'item/depend'}// ChildPropList ?! :s
]}),
RESULT:


DATA = [
{
"name":"typeBasic",
"id" :0
"ItemsChilds":"",
"depend":""
},{
"name : "typeChildsProp",
"id" :20
"ItemsChilds":"",
"depend":"" //empty!!! :(
},{
"name : "typeChildsItems",
"id" :10
"ItemsChilds":"",// empty!!! :(
"depend":""
}]
someone can help me?! :S

thanks!! and... sorry for my english!!

Condor
6 Nov 2009, 3:40 AM
So you want something like:

{name: 'depend', convert: function(value, record){
var nodes = Ext.DomQuery.select('depend', record);
var result = [];
for(var i = 0, len = nodes.length; i < len; i++){
var node = nodes[i];
result.push({
id: node.getAttribute('id'),
name: node.getAttribute('name')
});
}
return result;
}}