var adddata = [];
adddata[ group ] = [];
adddata[ group ][ id ] = option; // option is an object like { foo : 'bar' }
console.log( adddata ); // looks ok
$.cookie( 'cookiename', JSON.stringify( adddata ) );
console.log( $.cookie( 'cookiename' ) ); // just "[]"
$.cookie( 'cookiename', adddata );
console.log( $.cookie( 'cookiename' ) ); // "an empty string"
// in another file
var cdata = JSON.parse( $.cookie( 'cookiename' ) );
$.each( cdata, function( group, items ){
/* and so on */
});
如您所见,我使用 $.cookie 插件。但是我怎样才能以正确的方式将数组存储到 cookie 中呢?
谢谢和问候,亚历克斯