【问题标题】:Save the edited tree as a json object in the original format将编辑后的树保存为原始格式的 json 对象
【发布时间】:2017-04-07 03:39:44
【问题描述】:
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
    }]
}]
}

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

【问题讨论】:

    标签: javascript json ecmascript-6 treemodel


    【解决方案1】:
    JSON.stringify(root.model);
    

    解决了我的问题,找到了答案 Transforming a tree back to JSON using tree-model-js 和 Cloning a JS TreeModel tree

    非常感谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多