简体   繁体   中英

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);" line.

Please find my code and the error below. How can I overcome this error?

Error :

Uncaught TypeError: Converting circular structure to 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)

Example: oldLogs=logs.splice(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM