递归.js 773 B

12345678910111213141516171819202122232425262728293031323334
  1. function loadList() {
  2. this.listLoading = true;
  3. const params = {
  4. orgId: this.form.orgId,
  5. };
  6. API_EMP.selectRegisterVirt(params)
  7. .then((res) => {
  8. if (res.data?.length) {
  9. const getRecord = (data, level) => {
  10. const children = data.childList || [];
  11. const current = {
  12. level,
  13. value: data.id,
  14. label: data.nameinfo,
  15. children,
  16. };
  17. if (children?.length) {
  18. current.children = children.map((v) => getRecord(v, level + 1));
  19. }
  20. return current;
  21. };
  22. const dataSource = res.data.map((item) => getRecord(item, 0));
  23. this.list = dataSource;
  24. }
  25. })
  26. .finally(() => {
  27. this.listLoading = false;
  28. });
  29. }