File tree Expand file tree Collapse file tree 3 files changed +9
-12
lines changed Expand file tree Collapse file tree 3 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -579,7 +579,7 @@ $grid->column('name')->itemSuffix("折")
579
579
580
580
581
581
582
- ### 树形列表
582
+ ## 树形列表
583
583
584
584
> 用清晰的层级结构展示信息,可展开或折叠。
585
585
@@ -595,11 +595,12 @@ public function children() {
595
595
``` php
596
596
$grid->model()->where('parent_id', 0);//设置查询条件
597
597
$grid->tree();//启动树形表格
598
+ $grid->rowKey('id');//设置rowKey,必须存在,默认为ID,如果你的Grid没有定义ID字段就要重新设置其他字段
598
599
$grid->defaultExpandAll();//默认展开所有行
599
600
```
600
601
601
602
602
- ### 关联模型
603
+ ## 关联模型
603
604
> 要成功显示关联模型的值,必须设置` with ` 的值
604
605
605
606
要显示关联模型的值,使用` . ` 来获取关联模型的值,可以多级显示,最后一级为要显示的值
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ protected function grid()
79
79
->emptyText ("暂无菜单 " )
80
80
->defaultExpandAll (false );
81
81
82
+ $ grid ->column ('id ' , "ID " )->width (80 );
82
83
$ grid ->column ('icon ' , "图标 " )->component (Icon::make ())->width (80 );
83
84
$ grid ->column ('title ' , "名称 " );
84
85
$ grid ->column ('order ' , "排序 " );
Original file line number Diff line number Diff line change @@ -413,18 +413,13 @@ protected function displayData($data)
413
413
data_set ($ item , $ column ->getName (), $ n_value );
414
414
}
415
415
}
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
-
426
416
data_set ($ item , 'grid_actions ' , $ this ->grid ->getActions ($ row , $ key ));
427
417
418
+ //如果存在下级
419
+ if ($ TreeChildren = data_get ($ row , $ this ->grid ->getTreeChildrenName ())) {
420
+ //递归处理下级列表
421
+ data_set ($ item , $ this ->grid ->getTreeChildrenName (), $ this ->displayData ($ TreeChildren ));
422
+ }
428
423
$ items ->push ($ item );
429
424
}
430
425
You can’t perform that action at this time.
0 commit comments