| | |
| | | ) { |
| | | searchAll = JSON.parse(sessionStorage.getItem("menuList")); |
| | | } |
| | | // 过滤数组并生成新的数组对象 |
| | | //console.log(searchAll); |
| | | if (searchAll.length > 0) { |
| | | this.restaurants = searchAll.flatMap((menuItem) => { |
| | | return menuItem.orderNum > 0 && menuItem.list |
| | | ? menuItem.list |
| | | .filter((item) => item.url.trim() !== "") |
| | | .map((item) => ({ |
| | | value: item.name, |
| | | url: item.url, |
| | | })) |
| | | : []; |
| | | const items = []; |
| | | const walk = (nodes) => { |
| | | if (!nodes) return; |
| | | nodes.forEach((node) => { |
| | | if (node.url && node.url.trim() !== "") { |
| | | items.push({ value: node.name, url: node.url }); |
| | | } |
| | | if (node.list && node.list.length) { |
| | | walk(node.list); |
| | | } |
| | | }); |
| | | }; |
| | | searchAll.forEach((root) => { |
| | | if (root.orderNum > 0) { |
| | | walk(root.list || []); |
| | | } |
| | | }); |
| | | this.restaurants = items; |
| | | } |
| | | }, |
| | | }, |