0

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.

Any help is much appreciated.

$(".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!");
                }
            }
        );
    });
4
  • Did you really mean to comment out that block of code in the middle? Commented Dec 3, 2012 at 20:17
  • Log in the console the content of newarr before stringify, maybe with this you see the circular reference. Commented Dec 3, 2012 at 20:18
  • Sorry, that wasn't the problem I was having, but I updated the code Commented Dec 3, 2012 at 20:18
  • Can you post a screenshot of the expanded object from calling console.log(newarr) Commented Dec 3, 2012 at 20:19

1 Answer 1

3

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() ;
Sign up to request clarification or add additional context in comments.

1 Comment

@jrubins .. Glad to have helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.