easyUI批量刪除,向後臺傳陣列
easyUI做批量刪除時,向後臺傳送陣列
前臺程式碼:
<table id="dg" class="easyui-datagrid" title="分行資訊" style="width:1200px;height:450px"
data-options="
rownumbers:true,
singleSelect:true,
url:'${ctx}/branchAjax',
method:'get',
autoRowHeight:false,
pagination:true,
pageSize:10,
toolbar:'#tb'">
<thead>
<tr>
<th data-options="field:'id',checkbox:true">ID</th>
<th data-options="field:'branch_code',width:100">分行編碼</th>
<th data-options="field:'branch_name',width:80,align:'right'">分行名稱</th>
<th data-options="field:'simple_name',width:80,align:'right'">分行簡稱</th>
<th data-options="field:'english_name',width:220">外文名稱</th>
<th data-options="field:'district_code',width:220">地區編碼</th>
<th data-options="field:'create_date',width:220">成立日期</th>
<th data-options="field:'branch_state',width:60,align:'center'">狀態</th>
</tr>
</thead>
</table>
js程式碼:
function deleteDate(){
var rows = $('#dg').datagrid('getSelections');var ids = new Array();
for(var i=0; i<rows.length; i++){
ids.push(rows[i].id);
}
$.ajax({
type: "POST",
url: "${ctx}/deleteBranch",
data: { "ids": ids},
dataType: "json",
traditional: true,
success: function(data){
window.location.reload();
},
error : function() {
alert("異常!");
}
});
}
後臺接收程式碼:
public void deleteBranch(int[] ids, HttpServletRequest request) {
for (int i : ids) {
tBrenchService.deleteBranch(i);
}
}