1.在 public\assets\js\backend 目錄中找到對應的js,修改
2.對應控制器中加上index()方法;開啟關聯查詢
重點:
protected $relationSearch = true; //開啟關聯查詢
public function index()
{
//設置過濾方法
$this->request->filter(['strip_tags']);
//當前是否為關聯查詢
$this->relationSearch = true; // 解決排序問題
if ($this->request->isAjax()) {
//如果發送的來源是Selectpage,則轉發到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['choice'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['choice'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
3.對應模型中model 中加上關聯的方法
public function choice()
{
return $this->belongsTo('Choices', 'dw_id', 'id', [], 'LEFT')->setEagerlyType(0); // Choices ------- 需要關聯的模型 ; dw_id ----- 外鍵id ; id ------ 關聯表的id
}
4. 最終效果圖
5.最后還有些小問題,為什么做了以上的步驟之后,只顯示字段名,最后一步,同步語言包,把需要用的語言同步即可
詳細文檔,可查
https://doc.fastadmin.net/docs/controller.html#關聯查詢-5