第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

刪除功能無法正常工作選中所有復選框

刪除功能無法正常工作選中所有復選框

一只萌萌小番薯 2022-05-21 17:10:28
我在我的 spring 控制器中通過 ajax 調用傳遞了一組員工 ID 。function deleteEntries() {                var empList = $('input[type=checkbox]:checked').map(function (_, el) {                    return $(el).val();                }).get();                if (empList.length !== 0) {                    var r = confirm("Are you sure want to remove multiple entries? \nWarning: This process cannot be undone");                    if (r === true) {                        $.ajax({                            type: 'Post',                            url: baseUrl + 'delete_all',                            data: {                                empList: empList                            },                            success: function (successMsg) {                                location.reload();                            },                            fail: function (data) {                                unblockMyScreen();                                alert('Failed to retrieve data');                            }                        });                    }                } else                {                    alert("Choose atleast single record to delete.");                }            }.現(xiàn)在在 UI 中,我有復選框,我還提供了通過一次選擇全部并刪除來刪除的功能?,F(xiàn)在,當我全選并按下刪除按鈕時,只會刪除單個記錄。但是,如果不全選,它工作正常
查看完整描述

1 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

由于您的方法提前返回,因此只有一條記錄被刪除。要解決此問題,請創(chuàng)建一個布爾變量以返回方法控制,而不是返回 true/false,同時將長度減 1 以避免 ArrayIndexOutOfBoundsException。這是可能對您有所幫助的代碼片段


@RequestMapping(value = "/delete_all", method = RequestMethod.POST)

@ResponseBody

public boolean deleteMultipleRecord(@RequestParam(value = "empList[]", required = false) String[] empListToBeRemoved, HttpServletRequest request) {

    Employee emp = new Employee();

    for (int i = 0; i <= empListToBeRemoved.length-1; i++) {

        boolean result = false;

        if (!empListToBeRemoved[i].equals("0")) {

            emp.setEmpIdEnc(empListToBeRemoved[i]);

            try {

                List<OrgStructureTagging> list = orgStructureTaggingDAO.findEmpByProperty("EMP_ID", emp.getEmpId());

                for (OrgStructureTagging structureTagging : list) {

                    System.out.println("all ids of employees" + structureTagging.getEmployee().getName());

                    orgStructureTaggingDAO.delete(structureTagging);

                }

                result = true;

            } catch (Exception e) {

                e.printStackTrace();

                log.error("Error Occured While updating the field");

                result = false;

            }

        }

    }

    return result;

}


查看完整回答
反對 回復 2022-05-21
  • 1 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號