fastadmin 中添加自定义动态下拉框,并在前端展示出来

官方文档:

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>

更多的操作,请参考官方文档。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值