正在显示
1 个修改的文件
包含
29 行增加
和
0 行删除
| @@ -73,10 +73,39 @@ class NavController extends BaseController | @@ -73,10 +73,39 @@ class NavController extends BaseController | ||
| 73 | } | 73 | } |
| 74 | $result[] = $items; | 74 | $result[] = $items; |
| 75 | } | 75 | } |
| 76 | + foreach ($detailsList as $v){ | ||
| 77 | + if($v['pid'] == 0){ | ||
| 78 | + $result[] = $v; | ||
| 79 | + }else{//放到对应的上级下面 | ||
| 80 | + $this->addUnderParent($result,$v); | ||
| 81 | + } | ||
| 82 | + } | ||
| 76 | return $result; | 83 | return $result; |
| 77 | } | 84 | } |
| 78 | 85 | ||
| 79 | /** | 86 | /** |
| 87 | + * Add the current item under its parent in the result array | ||
| 88 | + * | ||
| 89 | + * @param array $result | ||
| 90 | + * @param array $item | ||
| 91 | + */ | ||
| 92 | + private function addUnderParent(&$result, $item) { | ||
| 93 | + $parentId = $item['pid']; | ||
| 94 | + foreach ($result as &$parent) { | ||
| 95 | + if ($parent['id'] == $parentId) { | ||
| 96 | + if (!isset($parent['sub'])) { | ||
| 97 | + $parent['sub'] = []; | ||
| 98 | + } | ||
| 99 | + $parent['sub'][] = $item; | ||
| 100 | + return; | ||
| 101 | + } | ||
| 102 | + if (!empty($parent['sub'])) { | ||
| 103 | + $this->addUnderParent($parent['sub'], $item); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 80 | * @remark :获取当前id下的所有子集 | 109 | * @remark :获取当前id下的所有子集 |
| 81 | * @name :getSubList | 110 | * @name :getSubList |
| 82 | * @author :lyh | 111 | * @author :lyh |
-
请 注册 或 登录 后发表评论