字典递归过滤
Showing
1 changed file
with
14 additions
and
8 deletions
1 | /* | 1 | /* |
2 | * @Description: | 2 | * @Description: |
3 | * @Autor: renchao | 3 | * @Autor: renchao |
4 | * @LastEditTime: 2023-07-03 08:59:06 | 4 | * @LastEditTime: 2023-08-16 11:30:45 |
5 | */ | 5 | */ |
6 | import store from '@/store' | 6 | import store from '@/store' |
7 | 7 | ||
... | @@ -27,12 +27,18 @@ export function getSjlx (level) { | ... | @@ -27,12 +27,18 @@ export function getSjlx (level) { |
27 | */ | 27 | */ |
28 | export function getDictLeabel (level, code) { | 28 | export function getDictLeabel (level, code) { |
29 | const resultMap = store.getters.dictData[code] | 29 | const resultMap = store.getters.dictData[code] |
30 | const desiredObject = resultMap.find(obj => obj.dcode === level); | 30 | function findNode(tree, func) { |
31 | 31 | for (const node of tree) { | |
32 | if (desiredObject) { | 32 | if (func(node)) return node |
33 | const desiredName = desiredObject.dname; | 33 | if (node.children) { |
34 | return desiredName | 34 | const res = findNode(node.children, func) |
35 | } else { | 35 | if (res) return res |
36 | return '' | 36 | } |
37 | } | ||
38 | return {dname:""} | ||
37 | } | 39 | } |
40 | let data = findNode(resultMap, (node) => { | ||
41 | return node.dcode === level | ||
42 | }) | ||
43 | return data.dname | ||
38 | } | 44 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment