Skip to content

Commit

Permalink
修复 Grid Tree 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallRuralDog committed Mar 31, 2020
1 parent 2898774 commit f6c54dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
5 changes: 3 additions & 2 deletions docs/grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ $grid->column('name')->itemSuffix("折")



### 树形列表
## 树形列表

>用清晰的层级结构展示信息,可展开或折叠。
Expand All @@ -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`的值
要显示关联模型的值,使用`.`来获取关联模型的值,可以多级显示,最后一级为要显示的值
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', "排序");
Expand Down
15 changes: 5 additions & 10 deletions src/Grid/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit f6c54dc

Please sign in to comment.