简体   繁体   English

将圆形结构转换为JSON-将元素数组复制到另一个数组并返回到原始数组时出错

[英]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.

相关问题 TypeError:通过快递发送数组时将循环结构转换为 JSON - TypeError: Converting circular structure to JSON when sending array via express 保存具有Parse.files数组的Javascript对象会导致“将循环结构转换为JSON”错误 - Saving Javascript object that has an array of Parse.files causes “Converting circular structure to JSON” error PolymerJS:将项目数组传递给函数-未捕获的TypeError:将圆形结构转换为JSON - PolymerJS: Pass array of items to function - Uncaught Typeerror: Converting circular structure into JSON 在更改子数组时将子数组复制到另一个数组中? - Copying subarrays into another array while changing them? JavaScript 数组映射,同时保留数组中的原始元素 - JavaScript array map while keeping original elements in the array 将一个数组复制到另一个数组 - copying one array to another array 云函数错误:将循环结构转换为 JSON - Cloud functions error: Converting circular structure to JSON kickoutJS错误:将圆形结构转换为JSON - knockoutJS error: Converting circular structure to JSON 将圆形结构转换为 JSON 时出错...采取 2 - Error Converting Circular Structure to JSON...take 2 简单查询将圆形结构转换为json错误 - converting circular structure to json error on simple query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM