layui批量删除关于前后台的传参

js的以及样式的引入这里不做说明,仅仅是实现layui批量删除关于前后台的写法

这里写图片描述

 table.render({
elem: '#**demo**'
,height: 420
,url: '/demo/table/user/' //数据接口
,title: '用户表'
,page: true //开启分页
,toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
,totalRow: true //开启合计行
,cols: [[ //表头
  {type: 'checkbox', fixed: 'left'}
  ,{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left', totalRowText: '合计:'}
  ,{field: 'username', title: '用户名', width:80}
  ,{field: 'experience', title: '积分', width: 80, sort: true, totalRow: true}
  ,{field: 'sex', title: '性别', width:80, sort: true}
  ,{field: 'score', title: '评分', width: 80, sort: true, totalRow: true}
  ,{field: 'city', title: '城市', width:150} 
  ,{field: 'sign', title: '签名', width: 200}
  ,{field: 'classify', title: '职业', width: 100}
  ,{field: 'wealth', title: '财富', width: 135, sort: true, totalRow: true}
  ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
]]  });

function delMany() {
var datas;
var id = new Array();//声明数组
layui.use(‘table’, function() {
var table = layui.table;
var checkStatus = table.checkStatus(‘demo’);//声明复选框
datas = checkStatus.data;
for(var i in datas) {
id[i] = datas[i].id;//得到复选框的值
}
});
$.ajax({
url: controller路径,
type: “POST”,
traditional: true,//传数组一定要加的
data: {
‘id’:id
},
dataType: “json”,
success: function(result) {
if(result.state == 1) {
alert(result.message);
location.reload();//刷新页面
} else {
alert(result.message);
location.reload();
}
},
});
}

猜你喜欢

转载自blog.csdn.net/sijielai6273/article/details/82656241