1
我有樹,從XML加載完全像this。如何從解析的Ext js樹中獲取JSON或XML?
此外,我啓用拖放。 現在通過拖放操作對樹進行更改後,我們應該可以獲取新數據,以便可以生成新的xml。
即使是JSON也會幫助重新生成新的xml。
我有樹,從XML加載完全像this。如何從解析的Ext js樹中獲取JSON或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。我會在服務器端..
希望有人也可以在它上面工作。