Transforming a tree back to JSON using tree-model-

2019-05-11 01:47发布

问题:

Is there perhaps a way in which you can convert a TreeModel to a JSON string. That way it can be stored and then later recreated using tree.parse()?

Currently when attempting JSON.stringify(root) it gives an obvious error about cyclic references (because children contain parents and parents contain children).

回答1:

Use JSON.stringify(root.model) instead.