From a9ea3412ce89ce2ccf3370dae0412be2ff462a68 Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 02:28:48 +0000 Subject: [PATCH 1/7] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=9D=A2=E8=AF=95?= =?UTF-8?q?=E9=A2=98=E8=A7=A3=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" diff --git "a/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" "b/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 4ca98495fe2310f9922177c6b6ccd27b40087ebc Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 02:29:03 +0000 Subject: [PATCH 2/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E9=9D=A2=E8=AF=95=E9=A2=98=E8=A7=A3=E7=AD=94/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" diff --git "a/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" "b/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From 7a6cb1ae3c880af721764ad53a7096af03f49847 Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 02:29:21 +0000 Subject: [PATCH 3/7] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E9=9D=A2=E8=AF=95?= =?UTF-8?q?=E9=A2=98=E8=A7=A3=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" diff --git "a/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" "b/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 3bc0087703ecf133ab6c0c94f98e2a441d670cb1 Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 02:29:51 +0000 Subject: [PATCH 4/7] =?UTF-8?q?add=20=E9=9D=A2=E8=AF=95=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E7=AD=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> --- .../jiajinwang.html" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/jiajinwang.html" diff --git "a/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/jiajinwang.html" "b/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/jiajinwang.html" new file mode 100644 index 0000000..e69de29 -- Gitee From 924906b0fdd34b67516f2b7b6621d2e19afe4981 Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 02:30:23 +0000 Subject: [PATCH 5/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E9=9D=A2=E8=AF=95=E9=A2=98=E8=A7=A3=E7=AD=94/jiajinwang.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jiajinwang.html" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/jiajinwang.html" diff --git "a/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/jiajinwang.html" "b/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/jiajinwang.html" deleted file mode 100644 index e69de29..0000000 -- Gitee From 09c2d866147334ee5c6edf367a9a49d0f03721ff Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 03:38:21 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E9=9D=A2=E8=AF=95=E9=A2=98=E8=A7=A3=E7=AD=94/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 "\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" diff --git "a/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" "b/\351\235\242\350\257\225\351\242\230\350\247\243\347\255\224/.keep" deleted file mode 100644 index e69de29..0000000 -- Gitee From 83f59512f97bfc8fcd431ed1413eee0dd532176d Mon Sep 17 00:00:00 2001 From: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> Date: Thu, 5 Jun 2025 03:39:33 +0000 Subject: [PATCH 7/7] =?UTF-8?q?=E9=9D=A2=E8=AF=95=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hubu-jiajinwang <13510554+hubu-jiajinwang@user.noreply.gitee.com> --- jiajinwang.html | 209 ++++++++++++++++++++++++++++++++++++++++++++++++ jiajinwang.js | 175 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 384 insertions(+) create mode 100644 jiajinwang.html create mode 100644 jiajinwang.js diff --git a/jiajinwang.html b/jiajinwang.html new file mode 100644 index 0000000..1f7518f --- /dev/null +++ b/jiajinwang.html @@ -0,0 +1,209 @@ + + + + + + 原生轮播图 + + + + + + + + + \ No newline at end of file diff --git a/jiajinwang.js b/jiajinwang.js new file mode 100644 index 0000000..159e61e --- /dev/null +++ b/jiajinwang.js @@ -0,0 +1,175 @@ +const cityData = [ + { + parentValue: 1, + value: 11, + label: '北京市', + }, + { + parentValue: 11, + value: 111, + label: '东城区' + }, + { + parentValue: 11, + value: 112, + label: '西城区' + }, + { + parentValue: 1, + value: 12, + label: '上海市', + }, + { + parentValue: 12, + value: 121, + label: '黄浦区' + }, + { + parentValue: 12, + value: 122, + label: '徐汇区' + }, + { + parentValue: 1, + value: 13, + label: '广东省', + }, + { + parentValue: 13, + value: 131, + label: '广州市', + }, + { + parentValue: 131, + value: 1311, + label: '天河区' + }, + { + parentValue: 131, + value: 1312, + label: '越秀区' + }, + { + parentValue: 132, + value: 1321, + label: '南山区' + }, + { + parentValue: 132, + value: 1322, + label: '罗湖区' + }, + { + value: 1, + label: '中国', + }, + { + parentValue: 13, + value: 132, + label: '深圳市', + } +] + +/* * + 1.请利用递归方法实现一个函数,把上方数据递归成有层级的数据, + 2.把value字段变成id字段,label字段变成title字段,children字段变成child字段, + 3.去掉parentValue字段,最终得到以下数据。需要一模一样的数据 + ⚠️注意:不允许使用三层循环,请使用递归方法 + [ + { + id: 1, + title: '中国', + child: [ + { + id: 11, + title: '北京市', + child: [ + { + id: 111, + title: '东城区' + }, + { + id: 112, + title: '西城区' + } + ] + }, + { + id: 12, + title: '上海市', + child: [ + { + id: 121, + title: '黄浦区' + }, + { + id: 122, + title: '徐汇区' + } + ] + }, + { + id: 13, + title: '广东省', + child: [ + { + id: 131, + title: '广州市', + child: [ + { + id: 1311, + title: '天河区' + }, + { + id: 1312, + title: '越秀区' + } + ] + }, + { + id: 132, + title: '深圳市', + child: [ + { + id: 1321, + title: '南山区' + }, + { + id: 1322, + title: '罗湖区' + } + ] + } + ] + } + ] + } +] + * */ + + +// 具体实现 +const getArea = (data, parentId = null) => { + const result = []; + + for (const item of data) { + if (item.parentValue === parentId || (parentId === null && item.value === 1)) { + const newItem = { + id: item.value, + title: item.label + }; + + const children = getArea(data, item.value); + if (children.length > 0) { + newItem.child = children; + } + + result.push(newItem); + } + } + + return result; +}; + +const result = getArea(cityData); +console.log(JSON.stringify(result, null, 2)); \ No newline at end of file -- Gitee