Cloning a JS TreeModel tree
问题 I need to clone a tree I made using TreeModel.js. What I exactly need to do is duplicating it, make changes to it and check if the number of nodes decreased. If it did, revert to the original tree. Here's a small example of what I do so far to duplicate it, which is not correct: var tree = new TreeModel(); var root = tree.parse({ id: 0, name: "Root", children: [{id: 1, name: "1", children: []},{id: 2, name: "2", children: []}] }); console.log(root) var dup = tree.parse(root) console.log(dup)