简体   繁体   中英

jqgrid json data array insert

In jqgrid, the part checked in the checkbox is brought into an array and inserted into the DB through VO.

I got the row data checked in jqgrid multiselect and pushed it into the declared array.

objGrid.click(function(){

            var data = objGrid.jqGrid('getGridParam','selarrrow');
            for(var i =0; i<data.length; i++)
            {

                empsl = objGrid.jqGrid('getCell', data[i], 'empno');
                /* empsl = JSON.parse(empsl); */
                arry.push(empsl);
            }


            test = JSON.parse(arry);
            //test = JSON.stringify(arry);

            console.log(test);


        });
},
        
        buttons : {
            "저장":function() {        
                console.log(typeof arry);
                console.log("insert data",arry);
                
                 if (isRunning) {
                    alert($.message.common.notification.wait);
                    return;
                }
                isRunning = true; 
            
                    $.post("./CheckHoliday/addCheckHolidayData"
                            , {empsl:arry} 
                            , function(data){
                                if (data > 0) {
                                    alert("has been saved.");
                                    closeDialogFunc();
                                    CheckHolidayListRefresh();

When I convert to JSON.stringify and press the save button, it comes in as an array well, but as you can see, even parentheses and quotation marks are entered as it is, and an error occurs.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '["10010","10010","10049"],
'Y'
)' at line 7

So, if you think you need to change it to JSON.parse(arry); and convert it to parse

If only one data is selected in the checkbox, it will be saved successfully, but if more than one checkbox is selected,

Uncaught SyntaxError: Unexpected token , in JSON at position 5 at JSON.parse () at HTMLTableElement.eval (eval at (jquery-1.8.3.js:564), :102:17) at HTMLTableElement.dispatch (jquery-1.8.3.js:3058) at HTMLTableElement.eventHandle (jquery-1.8.3.js:2676)

This error pops up in the developer tools console window, but I can't seem to put it into an array.

The end goal is to put the selected data into an array.

INSERT INTO HRS_CHECKHOLIDAY (
EMPNO
, EMPSL
, USEYN
) VALUES (
${empno},
${empsl},
'Y'
)

Isn't arry an object? So you cannot JSON.parse(arry) and you must get an error. Stringify arry then post the string. That should 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