直接上代码,找到对应的js文件,将button放入operate中即可(js在public/assets/js/backend/mod_renzheng.js),url即ajax的url,对应的是他自己的控制器名和方法名,后端就是简单的改status状态(0/1)
buttons: [
{
name: 'adopt',
text: '通过',
title: '通过',
classname: 'btn btn-xs btn-info btn-view btn-ajax',
icon: 'fa fa-check',
url: 'mod_renzheng/adopt',
visible: function (row) {
if (row['status'] == 0) {
return true;
} else {
return false;
}
},
refresh: true
},
{
name: 'cancel',
text: '取消通过',
title: '取消通过',
classname: 'btn btn-xs btn-warning btn-view btn-ajax',
icon: 'fa fa-times',
url: 'mod_renzheng/cancel',
visible: function (row) {
if (row['status'] == 2) {
return true;
} else {
return false;
}
},
refresh: true
}
],
代码样式
附上后端代码(application/admin/controller/ModRenzheng.php)
public function adopt()
{
$id = input('ids');
if ($id != null) {
$result = Db::table('car_mod_renzheng')->where('id', $id)->update(['status' => 2]);
$this->success('', '操作成功', $result);
}
}
public function cancel()
{
$id = input('ids');
if ($id != null) {
$result = Db::table('car_mod_renzheng')->where('id', $id)->update(['status' => 0]);
$this->success('', '取消成功', $result);
}
}