1.结构 list+total
return ['list' => $list, 'total' => $total];
list需要用limit分页,页码字段是pageNumber
2.赋值
如果获取到keyValue的值的话就根据值来做相应的where条件
在编辑页面初始化页面的时候,第一次会将关联id作为keyValue传到后台,点击选择框之后的异步调用则不会传keyValue
3.示例
public function query() { $account = Admin::get($this->auth->id); $page = $this->request->request('pageNumber')?:1; $param = input(); $id = (isset($param['keyValue'])&&$param['keyValue'])>0?$param['keyValue']:0; $zhi = 10; $tiao = ($page-1)*$zhi; $where = ['status' => 'normal']; if($account['position_ids']!="all"&&$account['position_ids']!=""){ $where['position_id'] = ["IN",$account['position_ids']]; } if($id>0){ $where['id'] = $id; } if($param['username']!="") $where['username'] = ['like',"%{$param['username']}%"]; $list = Db::name("user")->where($where)->field("id,username,position_id")->limit($tiao,$zhi)->select(); $total = Db::name("user")->where($where)->field("id,username,position_id")->count(); return ['list' => $list, 'total' => $total]; }