fastadmin 下拉框(单选)
1 mysql
2 js
{field: 'week', title: __('Week'), searchList: {"monday":__('Week monday'),"tuesday":__('Week tuesday'),"wednesday":__('Week wednesday')}, formatter: Table.api.formatter.normal}
3 add.html
<div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('Week')}:</label> <div class="col-xs-12 col-sm-8"> <select id="c-week" data-rule="required" class="form-control selectpicker" name="row[week]"> {foreach name="weekList" item="vo"} <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option> {/foreach} </select> </div> </div>
4 edit.html
<div class="form-group"> <label class="control-label col-xs-12 col-sm-2">{:__('Week')}:</label> <div class="col-xs-12 col-sm-8"> <select id="c-week" data-rule="required" class="form-control selectpicker" name="row[week]"> {foreach name="weekList" item="vo"} <option value="{$key}" {in name="key" value="$row.week"}selected{/in}>{$vo}</option> {/foreach} </select> </div> </div>
5 controller
public function _initialize() { parent::_initialize(); $this->model = new \app\admin\model\test\Test; $this->view->assign("weekList", $this->model->getWeekList()); }
6 model
public function getWeekList() { return ['monday' => __('Week monday'), 'tuesday' => __('Week tuesday'), 'wednesday' => __('Week wednesday')]; }