简体   繁体   中英

Setting 2-dimensional array into input hidden field

I have an array which I have another to push into in a loop

array1[ [box1, type1, 10], [box1, type2, 12] ]
array2[ [box2, type1, 10], [box2, type2, 12], [box2, type2, 12] ]

var curArray = new Array();

so in a loop:

var testarray = new Array('box1', 'type1', 10);
curArray.push(testarray);

and I have to post it so I set it in a hidden field. array.push works when I console.log(curArray) but if you set it to a hidden field by

$('hdnField').val(curArray)

it no longer become a multidimensional array.

Is there another way to do this?

尝试这个:

$('hdnField').val(JSON.stringify(curArray));

You can try JSON.stringify()

$('hdnField').val(JSON.stringify(curArray));

Does this work?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM