fastadmin下拉選擇框數據生成


下拉框數據生成
  • 模型里選擇數據

    public static function getTypeList()
        {
            $list=self::where(true)->select();
            $res=[];
            foreach ($list as $k=>$v){
                $res[$v['id']]=$v['name'];
            }
            return $res;
        }
    
  • 控制器的渲染數據

    public function _initialize()
        {
            parent::_initialize();
            $this->model = new \app\admin\model\yuyue\Schedule;
            $this->view->assign("TypeList", NewchatType::getTypeList());
        }
    
  • html里顯示數據

    <div class="form-group">
            <label class="control-label col-xs-12 col-sm-2">{:__('Typeid')}:</label>
            <div class="col-xs-12 col-sm-8">
    
                <select  id="c-typeid" data-rule="required" class="form-control selectpicker" name="row[typeid]">
                    {foreach name="TypeList" item="vo"}
                        <option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
                    {/foreach}
                </select>
    
            </div>
        </div>
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM