🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
:-: **添加form的控件Select** > addSelect * * * * * * 源代码 ~~~ /** * @title 添加一个Select组件 * @description 添加一个Select组件 * @createtime: 2018/7/11 01:22 * @param string $name 组件要使用的select的name true '' '' * @param string $label 组件前面展示的标题 true '' '' * @param array $list 需要显示的options,格式为[["text"=>"","value"=>"","checked"=>false]] false [] '' * @param string $placeholder 显示的placeholder false '' '' * @param array $info 数组承载图片内容,多张就[XX,XXX] false [] '' * @param array $options 直接渲染在input上面的各种attr,赋值value需要写在options内 false [] '' * @return Form */ public function addSelect($name, $label, $list = [], $placeholder = '', $info = [], $options = []){ $options = array_merge([ 'lay-verify' => '', 'required' => '', 'autocomplete' => "off", 'lay-search' => "", 'style' => "", 'name' => $name ], $options); $options = array_filter($options); //判断需不需要填充内容 if(isset($this->formValue[$name])){ $valueArr = is_array($this->formValue[$name])?$this->formValue[$name]:explode(",", $this->formValue[$name]); //只有不是空才回去运算,否则会出现 XX => '' if(!empty($valueArr)){ foreach($list as $i => $v){ if(in_array($v['value'], $valueArr)){ $list[$i]['checked'] = 1; } } } } return $this->addControl("select", $label, array_merge([ 'options' => $list, 'placeholder' => $placeholder, 'inline' => "layui-input-block", ], $info), $options); } ~~~ * * * * * 使用方法 ~~~ $form->addSelect("select", "选择器", [ ['text' => "123", "value" => 123, "checked" => true], ['text' => "1234", "value" => 1234], ]); ~~~