测试管理列表分类ID名称展示

samsam 3月前 260

image.png

实现功能步骤
1.application/admin/controller/Test.php代码修改
顶部引入

     use app\common\model\Category as CategoryModel;
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax())
        {

            //如果发送的来源是Selectpage,则转发到Selectpage
            if ($this->request->request('keyField'))
            {
                return $this->selectpage();
            }

            $typeName = CategoryModel::where('type', 'eq', 'test')
                ->column('id,name');

            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $list = collection($list)->toArray();

            foreach ($list as $k => &$v)
            {
                $v['type_text'] = isset($typeName[$v['category_id']]) ? $typeName[$v['category_id']] : "";
                $v['types_text'] = "";
                $cat = explode(',',$v['category_ids']);
                foreach($cat as $c){
                    $type[] = isset($typeName[$c]) ? $typeName[$c] : [];
                }
                $v['types_text'] = implode(',', $type);
            }
            unset($v);
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }

2.这里是列表文本修改plbilc/js/backend/test.js
定位修改的代码并替换

    {field: 'category_id', title: __('Category_id')},
    {field: 'category_ids', title: __('Category_ids')},
 替换成
    {field: 'type_text', title: __('Category_id'),formatter: Table.api.formatter.label},
    {field: 'types_text', title: __('Category_ids'),operate:false,formatter: Table.api.formatter.label},

喜欢这篇文章的点赞!!舍得给点零花钱的扫码!!最重要的是您开心、幸福美满!!!
zf.png

最后于 3月前 被samsam编辑
最新回复 (1)
返回