๐ ๋ฏธ๋ฃจ๊ณ ๋ฏธ๋ฃจ๋ ์ฒดํฌ๋ฐ์ค๋ก ๋ค์ค ์ญ์ ํ๊ธฐ ๐
function remove() {
let obj = document.querySelectorAll(".check"); //์ฒดํฌ ๋ฐ์ค -> class๊ฐ check
let idList = new Array();
for (let i = 0; i< obj.length; i++) {
if (obj[i].checked == true) {
// ์ฒดํฌ ๋ฐ์ค th:name="${member.id}"์ด๋ค. ์ฒดํฌ๋ ํญ๋ชฉ์ id๋ง idList์ ๋ฃ๊ธฐ
idList.push(obj[i].name);
}
}
$.ajax({
type: 'POST',
url: '/basic/members',
traditional: true,
dataType: 'text',
data: {
'ids': idList
},
}).done(function(res) {
idList.forEach((id) => {
let tr = document.querySelectorAll('.member');
// console.log(tr.textContent);
tr.forEach(elem => {
if (elem.getAttribute('id') === id) {
elem.parentElement.removeChild(elem);
}
})
})
}).fail(function (error) {
alert(JSON.stringify(error));
})
}
์ด๋ฐ ์์ผ๋ก ์๋ก๊ณ ์นจ ์์ผ๋ ๋์ง๋ง ์๋ก๊ณ ์นจ๋์ง ์๊ณ ํ๋ฉด์ด ์ ๋ฆฌ๋๋ ๊ฒ ๋ ๋์ด์ค ํ ๋ฐฉ๋ฒ์ด๋ผ ์๊ณ ์์ด์ผ ํ๋ค๊ณ ํ๋ค.
$.ajax({
type: 'POST',
url: '/basic/members',
traditional: true,
dataType: 'text',
// contentType: 'application/json; charset=utf-8',
data: {
'ids': idList
},
}).done(function(res) {
location.reload();
})
.fail(function (error) {
alert(JSON.stringify(error));
})
DB์๋ ์ ์ง์์ฃผ๊ธฐ
@PostMapping
public String multicheck(@RequestParam String ids, Model model) {
List<String> IDs = new ArrayList<String>(Arrays.asList(ids.split(",")));
for (String id : IDs) {
memberService.deleteMember(Long.parseLong(id));
}
return "redirect:/basic/members";
}
๐ ์๊ฒ๋ ์
๋ค์์
์์คํ
์ฅ์ ๊ฐ ์๊ฒผ์ ๋ ๋ณต๊ตฌํ ๋ฐฉ๋ฒ ์๊ฐํด ๋ณด๊ธฐ
์ปจํธ๋กค๋ฌ multicheck์์ ๋ฆฌ๋ค์ด๋ ํธ๊ฐ ์๋๋ ์ด์ -> location.reload();๋ฅผ ํด์ฃผ๋ฉด ํด๊ฒฐ