PDA

View Full Version : hi everyone,i'm the new guy for extjs4. i have problem with tree load xml file



david le
23 Oct 2012, 10:45 PM
my tree.js file code is


var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: './././data/treejson.xml',
reader:{
type:'xml',
root:'nodes',
record:'node'
}
},
root: {
text: 'root',
id: 'src',
expanded: true,
children: []
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
Ext.define('HT.view.treeDemo.Tree01',{
extend:'Ext.tree.Panel',
alias:'widget.tree01',
title: 'Simple Tree',
width: 200,
height: 150,
// store: Ext.data.StoreManager.lookup('treedemostore'),
store: store,
rootVisible: true,
tbar:[
{text:'memory xml',iconCls:'tj',id:'refresh_tree01',action:'refresh_tree011'},
{text:'xml file',iconCls:'xj',id:'refresh_tree02',action:'refresh_tree012'},
]
});


the folow file code is treejson.xml code



<nodes>
<node>
<text>tree1</text>
<leaf>true</leaf>
</node>

<node>
<text>tree2</text>
<expanded>true</expanded>
<children>
<text>tree21</text><leaf>true</leaf>
<text>tree22</text><leaf>true</leaf>
</children>
</node>

<node>
<text>tree3</text>
<leaf>true</leaf>
</node>

</nodes>


But running the results always have error,the second child(text tree2) couldn't load it's children. I don't know why,can anyone resolve it...thanks a lot

mitchellsimoens
25 Oct 2012, 10:54 AM
It's working for me if I change something around. You should not provide a single store instance in your Ext.define. If I remove it and add the store config to the tree instance it works:


Ext.define('HT.view.treeDemo.Tree01', {
extend : 'Ext.tree.Panel',
alias : 'widget.tree01',
title : 'Simple Tree',
width : 200,
height : 150,
rootVisible : true,
tbar : [
{text : 'memory xml', iconCls : 'tj', id : 'refresh_tree01', action : 'refresh_tree011'},
{text : 'xml file', iconCls : 'xj', id : 'refresh_tree02', action : 'refresh_tree012'}
]
});

Ext.application({
name : 'Test',

launch : function() {

var store = Ext.create('Ext.data.TreeStore', {
proxy : {
type : 'ajax',
url : 'data/xml.xml',
reader : {
type : 'xml',
root : 'nodes',
record : 'node'
}
},
root : {
text : 'root',
id : 'src',
expanded : true,
children : []
},
folderSort : true
});

new HT.view.treeDemo.Tree01({
renderTo : document.body,
store : store
});

}
});

david le
25 Oct 2012, 4:28 PM
Thank you for the anwser,but i don't know why. If i just change the url for loading the json file,it works...I have tried many times with memery json data and json file data ,it worked...Can anyone answer the diffrence betrween the xml file data and the json file data....Thanks very much.....