我遵循了本教程
http://fricardo.com/manipulando-cookies-com-jquery/
我将我的列表保存在 cookie 中:
jQuery.cookie('matrizTela', vList, {expires: 7});
但是,如果我在 console.log 中显示我的 cookie:
console.log(jQuery.cookie('matrizTela'));
我的返回是:
,[object Object]
为什么我的返回有“,”并且不打印我的对象列表?
PS:我的 vList 是 DOM 对象的矩阵
我需要什么?
我想保存一个矩阵(VLIST 中的 DOM 对象列表),然后通过此 cookie 检索 VLIST 并再次操作数据。
我的问题?
我的回信中有一个逗号。
最佳答案
插件似乎在内部调用您要存储的对象的 .toString()
。
如果你想正确存储它,我建议你做类似的事情
jsonList = JSON.stringify(vList);
jQuery.cookie('matrizTela', jsonList, {expires: 7});
Witch 会将你的对象转换为 json 字符串,例如:
JSON.stringify([1,2,3]) // "[1,2,3]"
然后,您可以像这样检索它:
jsonList = jQuery.cookie('matrizTela');
console.log( JSON.parse(jsonList) );
关于JQuery - 我如何在 cookie 中保存列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16775600/