The fastadmin framework implements tree classification and solves the problem of inaccurate display of the edit page classification and the classification structure problem

This project uses the tree-shaped classification that comes with fastadmin. If you take it and use it directly, the following problems will occur:
1. Uncompiled symbols will appear on the back-end classification list page
2. The editing page will show that the displayed classification is not correct. And the structure is chaotic

First of all, let's solve the relatively simple first problem. Here are two solutions:
First: directly in the corresponding category js, add escape:false,the special symbols of the list page so that there is no special symbol;
second: in the tree class Replace with  other symbols that do not need to be escaped, such as-and the like; the file location of the tree type is in extend/fast/Tree.php;

Secondly, we will solve the problem of incorrect display classification and structure confusion on the editing page: the
add page is displayed normally. In order not to affect the add page, we create a new method under the corresponding controller for editing page calls. The
default is indexMethod, we create a new idnex2method, the code is as follows:

/**
     * 查看
     */
    public function index2()
    {
    
    
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
    
    
            $search = $this->request->request("search");
            $type = $this->request->request("type");
            $keyValue = $this->request->request("keyValue",'');
            $keyField = $this->request->request("keyField");
            if($keyField=='id' && $keyValue){
    
    
                $list=db('itemclass')->where('id',$keyValue)->select();
                $total = count($list);
                $result = array("total" => $total, "rows" => $list);

                return json($result);
            }
            //构造父类select列表选项数据
            $list = [];

            foreach ($this->categorylist as $k => $v) {
    
    
                if ($search) {
    
    
                    if (stripos($v['name'], $search) !== false) {
    
    
                        $list[] = $v;
                    }
                } else {
    
    
                    $list = $this->categorylist;
                }
            }
            $total = count($list);
            $result = array("total" => $total, "rows" => $list);

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

Then call this method on the corresponding edit page

<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Class_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-class_id" data-rule="required" data-source="class/index2" class="form-control selectpage" name="row[class_id]" type="text" value="{$row.class_id|htmlentities}">
        </div>
</div>

In this way, the editing page can display the correct classification, and the classification style presents a tree structure.

Guess you like

Origin blog.csdn.net/qq_36129701/article/details/106687774