Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何调试JSON.stringify报告的循环引用_Jquery_Arrays_Json_Ecmascript 5 - Fatal编程技术网

Jquery 如何调试JSON.stringify报告的循环引用

Jquery 如何调试JSON.stringify报告的循环引用,jquery,arrays,json,ecmascript-5,Jquery,Arrays,Json,Ecmascript 5,调用JSON stringify时出现循环引用异常,但找不到循环引用。jQuery似乎是罪魁祸首,但我看不出问题所在,也无法介入JSON stringify const list = $('.use-in-reporting-checkbox:checkbox:checked').map(function() { return this.value; }); const dataPacket = { datasetIDs: list }; try { const r

调用JSON stringify时出现循环引用异常,但找不到循环引用。jQuery似乎是罪魁祸首,但我看不出问题所在,也无法介入JSON stringify

const list = $('.use-in-reporting-checkbox:checkbox:checked').map(function() 
{
    return this.value;
});

const dataPacket = {
    datasetIDs: list
};

try {
    const real = JSON.stringify(dataPacket);

} catch (error) {
    processError(error);
}

"Error reports: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    property 'selectorData' -> object with constructor 'Object'
    |     property 'elements' -> object with constructor 'Array'
    --- index 0 closes the circle"

But, inspection of dataPacket just shows: "datasetIDs init (37)" with the 
list of checkbox values. Not sure how to debug this.

发生此错误的原因是您获取的是jQuery对象而不是必需的值

-方法返回jQuery对象,该对象应通过get调用解析:

替代方法:

const ids = jQuery.map($('.use-in-reporting-checkbox:checkbox:checked'), function(v) 
{
    return v.id;
});

有道理。我会在周一测试这个。谢谢
const ids = jQuery.map($('.use-in-reporting-checkbox:checkbox:checked'), function(v) 
{
    return v.id;
});