fastadmin中动态下拉组件(SelectPage)的使用
实现的功能如下:
1、支持模糊搜索;2、分页功能;3支持多选
官方文档:https://doc.fastadmin.net/doc/178.html
html页面引用组件
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2"><span style="color: red;">*</span>{:__('世博园品牌推荐')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-tjbrand" class="form-control selectpage" name="row[tjbrand]"
data-source="/api/customer/index/brand"
data-multiple="true"
data-pagination="true"
data-page-size="10"
data-search-field="label"
data-field="label"
data-primary-key="value"
type="text" placeholder="世博园品牌推荐">
<span class="mailbox-attachment-size">下拉多选,支持模糊搜寻,数据来源:ERP系统</span>
</div>
</div>
后端数据接口写法(PHP)
public function brand(){
$parmas = $this->request->post();
// dump($parmas);
$where = "1=1";
if(!empty($parmas['label'])){
$where .= " and store_name like '%".$parmas['label']."%'";
}
$pageNumber = $parmas['pageNumber'];
$pageSize = $parmas['pageSize'];
$sql = "SELECT store_name as label,store_name as value FROM db_aimall_ffep_data.dl_store WHERE ".$where;
$total = count(self::db_erp()->query($sql));
$offset = $pageNumber==1 ? 1 : ($pageNumber-1)*$pageSize;
$data = self::db_erp()->query($sql." limit $pageSize offset $offset");
return json(['total'=>$total,'list'=>$data]);
}
注意的点是:
1、返回的数据格式按照文档的来;
2、如果是原生sql查询,用到分页的话,需要计算偏移量(offset);