Skip to content

Commit f6c54dc

Browse files
committed
修复 Grid Tree 问题
1 parent 2898774 commit f6c54dc

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

docs/grid.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ $grid->column('name')->itemSuffix("折")
579579

580580

581581

582-
### 树形列表
582+
## 树形列表
583583

584584
>用清晰的层级结构展示信息,可展开或折叠。
585585
@@ -595,11 +595,12 @@ public function children() {
595595
```php
596596
$grid->model()->where('parent_id', 0);//设置查询条件
597597
$grid->tree();//启动树形表格
598+
$grid->rowKey('id');//设置rowKey,必须存在,默认为ID,如果你的Grid没有定义ID字段就要重新设置其他字段
598599
$grid->defaultExpandAll();//默认展开所有行
599600
```
600601

601602

602-
### 关联模型
603+
## 关联模型
603604
>要成功显示关联模型的值,必须设置`with`的值
604605
605606
要显示关联模型的值,使用`.`来获取关联模型的值,可以多级显示,最后一级为要显示的值

src/Controllers/MenuController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protected function grid()
7979
->emptyText("暂无菜单")
8080
->defaultExpandAll(false);
8181

82+
$grid->column('id', "ID")->width(80);
8283
$grid->column('icon', "图标")->component(Icon::make())->width(80);
8384
$grid->column('title', "名称");
8485
$grid->column('order', "排序");

src/Grid/Model.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,13 @@ protected function displayData($data)
413413
data_set($item, $column->getName(), $n_value);
414414
}
415415
}
416-
417-
418-
if ($TreeChildren = data_get($item, $this->grid->getTreeChildrenName())) {
419-
$TreeChildren = collect($TreeChildren)->map(function ($t_item) use ($key, $row) {
420-
data_set($t_item, 'grid_actions', $this->grid->getActions($row, $key));
421-
return $t_item;
422-
})->all();
423-
data_set($item, $this->grid->getTreeChildrenName(), $TreeChildren);
424-
}
425-
426416
data_set($item, 'grid_actions', $this->grid->getActions($row, $key));
427417

418+
//如果存在下级
419+
if ($TreeChildren = data_get($row, $this->grid->getTreeChildrenName())) {
420+
//递归处理下级列表
421+
data_set($item, $this->grid->getTreeChildrenName(), $this->displayData($TreeChildren));
422+
}
428423
$items->push($item);
429424
}
430425

0 commit comments

Comments
 (0)