答案 0 :(得分:0)
function getJson(treeNode) {
treeNode.expandChildNodes();
var json = {};
var attributes = treeNode.attributes;
for(var item in attributes){
if (item == 'src' || item == 'text') { //only use required attributes
json[item] = attributes[item];
}
}
json.children = [];
if(treeNode.childNodes.length > 0){
for (var i=0; i < treeNode.childNodes.length; i++) {
json.children.push(getJson(treeNode.childNodes[i]));
}
}
return json;
}
// To use above function:
var comp = Ext.getCmp('tree-panel'); //id of the tree panel
var myJSON = getJson(comp.getRootNode());
console.log(Ext.encode(myJSON.children));
无法考虑创建XML。我会在服务器端制作..
希望有人也可以继续努力。