How To Save An Object With Circular References?
Solution 1:
Check out Crockford's JSON-JS GitHub repo. It has a file, cycle.js
, which can supposedly convert objects with circular references to JSON and back using JSONPath. See the last paragraph in the repo's read me and the file's comments.
Solution 2:
The answer here lies in understanding what data you really need to store persistently and minimizing that to only what is needed and then adding a method or function to get just that information and then saving that. I don't know your application but for a text selection, you would probably just need a persistent indication of which object it was and the start and end points of the text selection.
Then, on the restore side, you would build a function to build a selection using the data you store. It's not as simple a serialize/deserialize, but it will work.
Post a Comment for "How To Save An Object With Circular References?"