gpt4 book ai didi

javascript - 在javascript中提交二维数组

转载 作者:行者123 更新时间:2023-12-03 11:41:49 25 4
gpt4 key购买 nike

checkdata['attendance_batch'] = [
{user_id_c: 'abcda', ispresent: 0},
{user_id_c: 'abxcda', ispresent: 2},
{user_id_c: 'abctda', ispresent: 1}
]

我希望我的数组在 javascript 中采用上述格式

我的 HTML:

<label for='flip'>" + entry["name"] + "</label><div id='switch'><select name='user_id_c' id='flip2b' iduser='"+entry["id"]+"' data-role='slider'><option value='1'>Present</option><option value='0'>Absent</option></select>


$("#frmattendance").submit(function(event) {


event.preventDefault();
$form = $(this);

var a = {};

var paramString = [];
$($form).find(':input').each(function() {

//console.log($(this).attr('name'));
if ($(this).val() == 'Mark') {
}

else {

a[{user_id_c: $(this).attr('iduser'), ispresent: $(this).val()}];
// console.log(a[$(this).attr('name')]);
}

});

var $sessiondata = sessionStorage.sessionid;


$.ajax
({
type: "POST",
url: saverecordurl + 'pcc_attendance',
dataType: 'json',
async: false,
// session_id: $sessiondata,
//json object to sent to the authentication url
data: {checkdata: a, session_id: $sessiondata},
success: function(response) {
//console.log(response);
if (response.id !== null)
{

alert("You have successfully marked the attendance");

$.mobile.changePage("#eventdetails", {
transition: "slide",
reverse: true,
changeHash: true
});

}

},
error: function(result) {
$.mobile.changePage("#one", {
transition: "slide",
reverse: false,
changeHash: true
});
}

})

});

有人可以帮我解决格式错误吗?

最佳答案

a[{user_id_c: $(this).attr('iduser'), ispresent: $(this).val()}]; 是无效语法。您可以执行以下操作之一:

var a = {
user_id_c: $(this).attr('iduser'),
ispresent: $(this).val()
}

var a = {}
...
a.user_id_c = $(this).attr('iduser');
a.ispresent = $(this).val()

关于javascript - 在javascript中提交二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26243576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com