我有 Tree,从 XML 加载,就像这样。
此外,我启用拖放。现在通过拖放对树进行更改后,我们应该能够获取新数据,以便我可以生成新的 xml。
甚至 JSON 也有助于重新生成新的 xml。
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。我会在服务器端制作它..
希望有人也可以为它工作。