資料狀態的批量處理,ajax實現
阿新 • • 發佈:2018-12-10
//複選框新增
<th >
<span>全選<input type="checkbox" id="checkall" name="checkall" onclick="checkAll(checkall)" /></span>
</th>
<td >
<input type="checkbox" id=' ${item.zj}' name='info' value= '${item.zj}' />
</td>
//全選
function checkAll(checkall) {
arr = document. getElementsByName('info' );
if (checkall.checked == true) {
for(i=0;i<arr.length;i++){
arr[i].checked = true;
}
}else{
for(i=0;i<arr.length;i++){
if((arr[i]).checked==false){
arr[i].checked = true;
}else
{arr[i].checked = false; }
}
}
}
//批量操作某一個狀態
function checkAllConfirmFundinfo(datastatus){
//判斷至少選擇一項
var checkedNum = $("input[name='info']:checked").length;
if(checkedNum==0){
alert("請至少選擇一項!");
return false;
}
var checkedList = new Array();
$("input[name='info']:checked").each(
function(){
checkedList. push($(this).val());
});
$.ajax({
url: '${base}/fundraiselist/checkAllAjaxDatastatus',
type: "POST",
data:{
"delitems":checkedList.toString(),
"entity.datastatus":datastatus
},
success:function(data){
location.reload();
}
});
}
@Controller
@RequestMapping("/checkAllAjaxDatastatus")
public void checkAllAjaxDatastatus(FundRaiseListVO vo,HttpServletRequest request,
HttpServletResponse response){
String items = request.getParameter("delitems");
service.cheeckAllUpdateSelective(items,vo.getEntity());
}
@Service
public void cheeckAllUpdateSelective(String items,FundRaiseList entity) {
String[] strs = items.split(",");
for (int i = 0; i < strs.length; i++) {
String id = strs[i];
entity.setId(id);
mapper.updateSelective(entity);
}
}