diff --git a/ZhangJunjie.html b/ZhangJunjie.html new file mode 100644 index 0000000000000000000000000000000000000000..dcae8086c1d12560fc9156258b188c706dc1c7ec --- /dev/null +++ b/ZhangJunjie.html @@ -0,0 +1,169 @@ + + + + + + + Document + + + + +
+
+ + + + +
+
+
+
+ + + + +
+
+ + + \ No newline at end of file diff --git a/ZhangJunjie.js b/ZhangJunjie.js new file mode 100644 index 0000000000000000000000000000000000000000..6955bd9cf20ea0753f814b90b6938e531d511cd9 --- /dev/null +++ b/ZhangJunjie.js @@ -0,0 +1,93 @@ +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: '深圳市', + } +] + +const getArea = (data, parentId = null) => { + const result = []; + for (const item of data) { + if ((parentId === null && !item.parentValue) || + (item.parentValue === parentId)) { + const node = { + id: item.value, + title: item.label, + child: getArea(data, item.value) + }; + if (node.child.length === 0) { + delete node.child; + } + result.push(node); + } + } + return result; +} + +const result = getArea(cityData); +console.log(JSON.stringify(result, null, 2)); \ No newline at end of file diff --git "a/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (1).png" "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (1).png" new file mode 100644 index 0000000000000000000000000000000000000000..39a51beaa5c403397d49faa61474ed737f0bd28a Binary files /dev/null and "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (1).png" differ diff --git "a/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (2).png" "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (2).png" new file mode 100644 index 0000000000000000000000000000000000000000..7ce5aac953ab89c6eb84f7ac2fa81019dec449af Binary files /dev/null and "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (2).png" differ diff --git "a/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (3).png" "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (3).png" new file mode 100644 index 0000000000000000000000000000000000000000..29d3d27dc160fbb000fda66f9405f3430a62db51 Binary files /dev/null and "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (3).png" differ diff --git "a/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (4).png" "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (4).png" new file mode 100644 index 0000000000000000000000000000000000000000..4a723ed13bb8e5a0816da9519657b9fa745aa4f6 Binary files /dev/null and "b/\345\210\266\344\275\234\345\217\214\345\215\201\344\270\200\350\275\256\346\222\255\345\233\276 (4).png" differ