[英]Converting circular structure to JSON - error while copying array of elements to another array and return back to original array
I have a requirement to copy array of elements to temporary array and again return back to the original array. 我需要将元素数组复制到临时数组,然后再次返回到原始数组。 Finally i have to save all the state items. 最后,我必须保存所有状态项。
But while do this process am getting error 但是虽然这个过程出现错误
"Converting Circular structure to JSON" in
"this.props.save(this.state.item);"
“"this.props.save(this.state.item);"
“将循环结构转换为JSON"this.props.save(this.state.item);"
line. 线。
Please find my code and the error below. 请在下面找到我的代码和错误。 How can I overcome this error? 我该如何克服这个错误?
Error : 错误:
Uncaught TypeError: Converting circular structure to JSON 未捕获的TypeError:将圆形结构转换为JSON
Please find my code below. 请在下面找到我的代码。
handleAutoSplit(e) {
e.preventDefault();
var logs=item.order_logs;
var oldLogs =[];
oldLogs.push(logs);
logs.push.apply(logs,oldLogs);
this.props.save(this.state.item);
}
Below changes worked for me. 下面的变化对我有用。
Instead of .push(), have to use .splice(0) 代替.push(),必须使用.splice(0)
Example: oldLogs=logs.splice(0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.