js递归调用&多层if else嵌套,返回值为空或undefined问题

// 递归遍历数据获取当前实体名称
    recursionChildren(arr, node) {
      let name = "";
      arr.forEach((item) => {
        let temp = { ...item };
        if (temp.children && temp.children.length > 0) {
          if (temp.id == node) {
            name = temp.label;
          } else {
            let result = this.recursionChildren(temp.children, node);
            if (result) {
              name = result;
            }
          }
        } else {
          if (temp.id == node) {
            name = temp.label;
          }
        }
      });
      return name;
    },

你可能感兴趣的:(javascript,前端,html)