react 项目 合并单元格解决方案

// 右侧产品列表
  getProductList (){
    http({
      method: 'get',
      url: '/v2/activity/productAdaptationRecommendRight',
      data: {
      //   sessionId: this.state.sessionId,
      //   tenantId: 'tenant_system'
      }
    }).then((res) => {
      let arr = res.data.data
      let newarr = arr.map(item => item.product_name)
      let newnewarr = [... new Set(newarr)]
      // console.log(newarr)
      console.log('合并前的数组')
      let narr = []
      const proList = arr.reduce((result, item,index) => {
        if (result.indexOf(item.product_name) < 0) {
          result.push(item.product_name)
        }
        return result
        }, []).reduce((result, product_name) => {
        const children = arr.filter(item => item.product_name === product_name)
        // console.log(children)
        result = result.concat(
          children.map((item, index) => ({
            ...item,
            rowSpan: index === 0 ? children.length : 0
          }))
        )
        return result;
        }, []);
        console.log("合并后的新数组")
        console.log(proList)
        this.setState({
          tableData: proList
        })
    })
  }
 
使用方法:
const columns = [
         {
          key: 'product_name',
          title: '产品',
          dataIndex: 'product_name',
          render: (text, record, index) => {
            const obj = {
              children: <span className='tdImg'><img src = {salesIcon} />{text}</span>,
              props: {},
            };
            obj.props.rowSpan = record.rowSpan
            obj.props.className = record.rowSpan === 0?'borderRightNone':'borderRightOne'
            return obj;
          },
        }
posted @   雪莉06  阅读(617)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示