Modify properties recursively

 // 递归  
      const filterdata = (data,id) => {
    
    
        // const {dimMapId } = data;

        const array = data.map((el) => {
    
    
          const {
    
     valueName, sonValue } = el;

          let item = {
    
    };
          if (valueName && valueName !== "null") {
    
    
            item = {
    
    
              // value: `${sonValue?.dimMapId || null}--${valueName}`,
              value: `${
    
    id},

              label: valueName,
            };
          }
          if (sonValue && Object.keys(sonValue).length) {
    
    
            item.children = filterdata(
              sonValue.valueList || [],
              sonValue.dimMapId,
            );
          }

          return item;
        });
        return array;
      };

Guess you like

Origin blog.csdn.net/mengfanyue123/article/details/122603907