簡體   English   中英

用JavaScript提交二維數組

[英]Submit a two dimensional array in javascript

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM