diff --git a/docs/grid.md b/docs/grid.md index 51d00ac..6b29353 100644 --- a/docs/grid.md +++ b/docs/grid.md @@ -579,7 +579,7 @@ $grid->column('name')->itemSuffix("折") -### 树形列表 +## 树形列表 >用清晰的层级结构展示信息,可展开或折叠。 @@ -595,11 +595,12 @@ public function children() { ```php $grid->model()->where('parent_id', 0);//设置查询条件 $grid->tree();//启动树形表格 +$grid->rowKey('id');//设置rowKey,必须存在,默认为ID,如果你的Grid没有定义ID字段就要重新设置其他字段 $grid->defaultExpandAll();//默认展开所有行 ``` -### 关联模型 +## 关联模型 >要成功显示关联模型的值,必须设置`with`的值 要显示关联模型的值,使用`.`来获取关联模型的值,可以多级显示,最后一级为要显示的值 diff --git a/src/Controllers/MenuController.php b/src/Controllers/MenuController.php index 1572e41..8e85d65 100644 --- a/src/Controllers/MenuController.php +++ b/src/Controllers/MenuController.php @@ -79,6 +79,7 @@ protected function grid() ->emptyText("暂无菜单") ->defaultExpandAll(false); + $grid->column('id', "ID")->width(80); $grid->column('icon', "图标")->component(Icon::make())->width(80); $grid->column('title', "名称"); $grid->column('order', "排序"); diff --git a/src/Grid/Model.php b/src/Grid/Model.php index fef379f..c7ae11f 100644 --- a/src/Grid/Model.php +++ b/src/Grid/Model.php @@ -413,18 +413,13 @@ protected function displayData($data) data_set($item, $column->getName(), $n_value); } } - - - if ($TreeChildren = data_get($item, $this->grid->getTreeChildrenName())) { - $TreeChildren = collect($TreeChildren)->map(function ($t_item) use ($key, $row) { - data_set($t_item, 'grid_actions', $this->grid->getActions($row, $key)); - return $t_item; - })->all(); - data_set($item, $this->grid->getTreeChildrenName(), $TreeChildren); - } - data_set($item, 'grid_actions', $this->grid->getActions($row, $key)); + //如果存在下级 + if ($TreeChildren = data_get($row, $this->grid->getTreeChildrenName())) { + //递归处理下级列表 + data_set($item, $this->grid->getTreeChildrenName(), $this->displayData($TreeChildren)); + } $items->push($item); }