We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 95ac54d commit db8ba30Copy full SHA for db8ba30
docs/front-end/13-project/04-角色管理页面.md
@@ -34,3 +34,30 @@ const labelOptions = ref({
34
35
```
36
37
+## 遍历获取需要属性
38
+
39
+```ts
40
+// 处理数据-获取根节点数据
41
+const filterMenuData = (original: any[]) => {
42
+ return original
43
+ .filter((item: any) => !item.pid) // 筛选 pid 为空的根节点
44
+ .map((item: any) => ({
45
+ id: item.id,
46
+ name: item.name,
47
+ pid: item.pid,
48
+ })); // 返回只包含 id、name、pid 的对象数组
49
+};
50
51
+// 示例数据
52
+const originalData = [
53
+ { id: 1, name: "根节点1", pid: null },
54
+ { id: 2, name: "子节点1", pid: 1 },
55
+ { id: 3, name: "根节点2", pid: null },
56
+ { id: 4, name: "子节点2", pid: 3 },
57
+];
58
59
+// 调用函数
60
+const rootNodes = filterMenuData(originalData);
61
+console.log(rootNodes);
62
+```
63
0 commit comments