fastadmin关联表,列表下拉查询搜索
1.获取下拉框显示数据,默认加载字段,id,name
public function source() { //$json = cache('ai_activity_type'); $json = false; if ($json === false) { $typeModel = new \app\admin\model\ai\ActivityType(); $list = $typeModel->field('id,name')->select(); $json = json($list); cache('ai_activity_type', $json); } return $json; }
2.修改JS文件中列表字段渲染方式
{field: 'type.name', title: __('Type.name'), operate: 'LIKE', searchList: $.getJSON("ai/activity_type/source")},
3.修改控制器中接收数据方式,声明一个新的where条件
$filter = $this->request->param("filter"); $filter_arr = json_decode($filter, true); $where2 = array(); if (isset($filter_arr['type.name']) && !empty($filter_arr['type.name'])) { $where2['type_id'] = $filter_arr['type.name']; unset($filter_arr['type.name']); }
4.fastadmin内置的buildparams,需要重写,复制一份代码,改写方法名称,修改新方法中的代码
$filter = $filter ? $filter : []; if (isset($filter['type.name']) && !empty($filter['type.name'])) { unset($filter['type.name']); }
到此即可完成代码操作