且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将一个带有循环引用的对象从服务器传递给客户端Javascript,同时保留循环

更新时间:2023-01-17 15:34:05

Douglas Crockford有一个解决方案以前我已经成功地解决了这个问题: Cycle.js

Douglas Crockford has a solution for this that I have successfully used to solve this problem before: Cycle.js

而不是使用 stringify parse c $ c> decycle 并使用 retrocycle 恢复

instead of just using stringify and parse you would first call decycle and restore with retrocycle

var jsonString = JSON.stringify(JSON.decycle(parent));
var restoredObject = JSON.retrocycle(JSON.parse(jsonString));

JSFiddle