가 나는 Ext.tree.TreePanel 객체가 있다고 가정하자의 ExtJS TreePanel에서 JSON 데이터 가져 오기, 그것은 데이터를 외부 파일에서로드 나무.전,
사용자가 트리에 새 노드를 추가하고 일부 노드를 이동시킵니다. 트리에서 JSON 데이터를 가져와 다음에 사용자가 트리를로드 할 때 사용할 수 있습니까?
EDIT (코드 솔루션) : 여기
후안의 반응에서 아이디어를 기반으로하는 솔루션이다. 미래에이 스레드를 발견하고 일부 코드를 찾고있는 경우에 대비하여이 코드를 사용하고 있습니다.
function getNodeList(bfsQueue) {
var node = bfsQueue.pop();
var nodeQueue = [];
for (var ii = 0; ii < node.childNodes.length; ii++) {
bfsQueue.push(node.childNodes[ii]);
nodeQueue.push(node.childNodes[ii]);
}
if (bfsQueue.length === 0) {
return nodeQueue;
} else {
return nodeQueue.concat(getNodeList(bfsQueue));
}
}
var startQueue = [];
var nodeList = [];
startQueue.push(tree.getRootNode());
nodeList.push(tree.getRootNode());
nodeList = nodeList.concat(getNodeList(startQueue));
console.dir(nodeList);
for (var nn = nodeList.length-1; nn >= 0; nn--) {
var params = [];
for (var pp in nodeList[nn].attributes) {
if (pp === "children" || pp === "loader") {continue;}
params.push('"' + pp + '":' + JSON.stringify(nodeList[nn].attributes[pp]) + '');
}
if (nodeList[nn].childNodes.length > 0) {
var childList = [];
for (var ii = 0; ii < nodeList[nn].childNodes.length; ii++) {
childList.push(nodeList[nn].childNodes[ii].json);
}
params.push('"children": [' + childList.join(',') + ']');
}
nodeList[nn].json = "{" + params.join(",") + "}";
}
console.log(nodeList[0].json); // root node
속성 속성에 대해 알지 못했습니다. 그것과 childNodes 배열은 필요한 것입니다. 정보 주셔서 감사합니다! – patorjk
속성은 데이터입니다. – Stevanicus
@Stevanicus Ext-JS 4.0 업데이트 주셔서 감사합니다. 문서화되지 않은 프로퍼티로 작업하지 않도록'.data' 프로퍼티에 직접 액세스하는 대신 모델 정의와'get/set' 인터페이스를 설정하는 것이 더 바람직합니다 –