今天写项目遇到了删除不了数据的情况,选择了多项数据进行删除,第一项总是报NaN错误,获取不了id,不知道是哪里出了问题?在这里请教一下老师们。
jsp页面代码:
{
text:"删除",
iconCls:"icon-remove",
handler:function(){
//找到datagrid表格中所选中的行
$("#tt").datagrid("reload",{});
var rows=$("#tt").datagrid("getSelections");
//alert($("tt").datagrid("getRowIndex"));
alert(rows);
if(rows.length<=0)
{
$.messager.show({
width:200,
height:100,
title:"提示信息",
msg:"至少要选择一条记录进行删除!"
});
}else{
for(var i=0;i<rows.length;i++)
{
var ids=ids+rows[i].id+","
}
//删除最后一个逗号
ids=ids.substring(0,ids.length-1);
alert(ids);
$.messager.confirm("确认信息","您确定要删除吗?",function(bol){
if(bol)
{
$.post("/project18/client/clientAction_delete","method=delete&ids="+ids,function(data){
$.messager.show({
width:200,
height:100,
title:"提示信息",
msg:data.message
});
//刷新datagrid
$("#tt").datagrid("unselectAll",{});
$("#tt").datagrid("reload",{});
},"json");
}else{
$("#tt").datagrid("clearSelections");
}
});
}
}
},
控制层代码:
@RequestMapping("clientAction_delete")
public void delete(HttpServletRequest request,HttpServletResponse response) throws IOException{
String ids=request.getParameter("ids");
System.out.println(ids);
String[] id=ids.split(",");
int[] idss=new int[id.length];
for(int i=0;i<id.length;i++){
idss[i]=Integer.parseInt(id[i]);
clientService.delete(CClient.class, idss[i]);
}
response.setContentType("json;charset=utf-8");
response.getWriter().print("{\"message\":\"删除成功\"}");
}
![图片说明](https://img-ask.csdn.net/upload/201710/24/1508845590_644337.png)