0
let data = {
"name": "root",
"children": [{
    "name": "analytics",
    "children": [{
        "name": "cluster",
        "children": [{
            "name": "AgglomerativeCluster",
            "size": 3938
        }]
    }, {
        "name": "graph",
        "children": [{
            "name": "BetweennessCentrality",
            "size": 3534
        }]
    }, {
        "name": "optimization",
        "children": [{
            "name": "AspectRatioBanker",
            "size": 7074
        }]
    }]
}]
};

let child1 = {
"name": "flex",
"children": [{
    "name": "FlareVis",
    "size": 4116
}]
};

let tree = new TreeModel();
let root = tree.parse(data);
//# Add a child
let tempChild1 = tree.parse(child1);
//# Add a child at a given index
root.addChildAtIndex(tempChild1, 0);
console.log(root);

使用这个库: http: //jnuno.com/tree-model-js/进行树操作。那么,如何在添加或删除后以原始格式从库中取回数据。

After the above operation, how can I get back this modified object from the library?
   data = {
"name": "root",
"children": [{
    "name": "analytics",
    "children": [{
        "name": "cluster",
        "children": [{
            "name": "AgglomerativeCluster",
            "size": 3938
        }]
    }, {
        "name": "graph",
        "children": [{
            "name": "BetweennessCentrality",
            "size": 3534
        }]
    }, {
        "name": "optimization",
        "children": [{
            "name": "AspectRatioBanker",
            "size": 7074
        }]
    }]
}, {
    "name": "flex",
    "children": [{
        "name": "FlareVis",
        "size": 4116
    }]
}]
}

图书馆有没有办法做到这一点,或者有没有一种有效的方法可以将其转换回所需的格式,即原始格式。

4

1 回答 1

0
JSON.stringify(root.model);

解决了我的问题,在 使用 tree-model-js 将树转换回 JSON克隆 JS TreeModel 树中找到了答案

太感谢了。

于 2017-04-07T03:54:15.540 回答