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("折")
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要显示关联模型的值,使用` . ` 来获取关联模型的值,可以多级显示,最后一级为要显示的值
Original file line number Diff line number Diff 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 ' , "排序 " );
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments