官方文档:
https://doc.fastadmin.net/doc/178.html
我写的某个下拉:
添加页面前端:
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Unit')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-unit" data-rule="required" data-source="source/unit/get_type_list" class="form-control selectpage" name="row[unit]" type="text" value="" data-field="title">
<!-- data-field属性,就是需要显示的值。默认是返回的字段name,不是name的话,就需要手动修改 -->
<!-- data-source属性,就是查询的方法 -->
</div>
</div>
方法:
//这里的方法名,即data-source的值,注意路径
public function get_type_list() {
$result = array("rows" => [], "total" => 0);
if ($this->request->isAjax()) {
if ($this->request->request("keyValue")) {
$id = $this->request->request("keyValue");
//这里的model,就是需要查找的那个数据库的模型,根据实际情况做更改
$type = $this->model;
$list = $type
->field("id,title")
//这里的条件,就是需要自己进行筛选的条件,根据实际情况做更改
//->where("firmid", $this->auth->firmid)
->where("id", $id)
->select();
return ['total' => 1, 'list' => $list];
}
//这里的model,就是需要查找的那个数据库的模型,根据实际情况做更改
$type = $this->model;
$list = $type
->field("id,title")
//这里的条件,就是需要自己进行筛选的条件,根据实际情况做更改
//->where("firmid", $this->auth->firmid)
->select();
$count = $type
//这里的title,就是前段需要展示的,即:data-field的值
->field("id,title")
//->where("firmid", $this->auth->firmid)
->count();
$result = array("rows" => $list, "total" => $count);
return json($result);
}
return json($result);
}
编辑页面前端:
<div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('Unit')}:</label> <div class="col-xs-12 col-sm-8"> <input id="c-unit" data-rule="required" data-source="source/unit/get_type_list" class="form-control selectpage" name="row[unit]" type="text" value="" data-field="title"> </div> </div>
更多的操作,请参考官方文档。