在下面的代码中,对于每个工作人员,我试图获取他们监督的组的 group_id 列表,然后我想对包含这些 id 的数组进行字符串化并将其发送出去以更新数据库。
但是,当我尝试对映射数组进行字符串化时,出现关于转换循环结构的错误。我不太明白下面代码中的循环是什么。
任何帮助深表感谢。
$(".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!");
}
}
);
});