fastadmin中Selectpage使用自定义的数据
astadmin默认使用的Selectpage是通过data-source的路径来获取数据的,这个一般都是从数据库中获取的,但是对于很多场景下,这里只需要一点简单的数据,没有必要再建立数据表,我们可以这么做
1、通过系统配置,添加新的变量到数据词典中,类型选择数组
2、在需要的页面添加如下的html
<div class="form-group form-input form-input-ad_type">
<label class="control-label col-xs-12 col-sm-2">跳转类型:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-ad_type" data-source="adszone/adType" data-field="ad_name"
data-primary-key="ad_type"
class="form-control selectpage" name="row[ad_type]" type="text" value="{$row.ad_type|htmlentities}">
</div>
</div>
3、注意上面的data-source,这个是一个数据请求的路径,我们在对应的php文件中添加相应的方法
/**
* Notes:获取广告位类型
* DateTime 2022/3/10 10:10
* @Author wind
* @return \think\response\Json|void
*/
public function adType()
{
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
$adType = Config::get('site.ad_type');
$list = [];
if ($this->request->request('keyValue')) {
$list[] = [
'ad_type' => $this->request->request('keyValue'),
'ad_name' => $adType[$this->request->request('keyValue')],
];
return json(['list' => $list, 'total' => count($list)]);
}
foreach ($adType as $k=>$v) {
$list[] = [
'ad_type' => $k,
'ad_name' => $v,
];
}
return json(['list' => $list, 'total' => count($list)]);
}
}
本文链接:
/archives/1703559154967
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
雕刻时光!
喜欢就支持一下吧