JSON字符串化圆形结构错误 [英] JSON stringify circular structure error

查看:100
本文介绍了JSON字符串化圆形结构错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我试图为每个工作人员获取他们所监管的组的group_id的列表,然后我想对包含这些ID的数组进行字符串化,然后将其发送以更新数据库.

In the below code, for each staff member I am trying to grab a list of the group_ids of groups they supervise and then I want to stringify the array containing those ids and send it off to update the database.

但是,当我尝试对映射数组进行字符串化处理时,出现关于转换圆形结构的错误.我在下面的代码中看不到什么是圆形的.

However, when I try to stringify the mapped array, I get an error about converting a circular structure. I don't quite see what is circular in the below code.

非常感谢您的帮助.

$(".staff_member").each(function() {
        var staff_id = $(this).attr("staff_id");

        var newarr = $(this).find(".staff_groups .staff_group").map(function() {
            return $(this).attr("group_id");
        });
        alert(JSON.stringify(newarr));
        $.post(
            "staff_update.php",
            { staff_id: staff_id, groups: newarr },
            function(data) {
                var response = jQuery.parseJSON(data);
                if(response.code == "success") {
                    alert("Done!");
                } else if(response.code == "failure") {
                    alert("Failure!");
                }
            }
        );
    });

推荐答案

首先将其转换为数组...map()返回 jQuery对象

Convert that to an array first .. .map() returns a jQuery Object

var newarr = $(this).find(".staff_groups .staff_group").map(function() {
            return $(this).attr("group_id");
        }).get() ;

这篇关于JSON字符串化圆形结构错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆