将编辑后的树另存为原始格式的 json 对象


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
    }]
}]
}

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

JSON.stringify(root.model);

解决了我的问题,在使用树模型js将树转换回JSON。和克隆 JS 树模型树

非常感谢。

相关内容

  • 没有找到相关文章

最新更新