Jquery 如何调试JSON.stringify报告的循环引用
调用JSON stringify时出现循环引用异常,但找不到循环引用。jQuery似乎是罪魁祸首,但我看不出问题所在,也无法介入JSON stringifyJquery 如何调试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
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;
});