总共可以看出是三层结构 所以要处理成对应的表头和表数据格式
数据处理过程
let arr: any = [] response.data && response.data.map((item: any, index: number) => { item.t_base_style && item.t_base_style.map((item1: any, index1: any) => { item1.t_base_part_region && item1.t_base_part_region.map((item2: any, index2: any) => { if(item2.t_qc_reference_standard.length==0){ arr.push({ part: item2.name, styleNumber: item1.name, product: item.name, styleId: item1.id, partId: item2.id, flag: item2.qc_flag, }) }else{ item2.t_qc_reference_standard&&item2.t_qc_reference_standard.map((item3:any,index3:any)=>{ arr.push({ part: item2.name, styleNumber: item1.name, product: item.name, styleId: item1.id, partId: item2.id, flag: item2.qc_flag, flagId:item3.id }) }) } }) })
操作要点1 形成column和datasource格式
<BasicTable data={menuData} onChange={onTableChange} loading={loading}> <Table.Column<Menu> title="品类" dataIndex="product" align="center"></Table.Column> <Table.Column<Menu> title="款式" dataIndex="styleNumber" align="center"></Table.Column> <Table.Column<Menu> title="部件" dataIndex="part" align="center"></Table.Column> <Table.Column<Menu> title="是否维护" dataIndex="flag" align="center" render={(text, record, index) => ( <span>{text ? "已维护" : "未维护"}</span> )}></Table.Column> <Table.Column<Menu> title="操作" align="center" render={(text, record, index) => ( <MenuButton index={index} record={record} onButtonClick={onButtonClick} /> )} ></Table.Column> </BasicTable>
操作要点2 查询数据
关键要有两份数据
setMenuData({ list: arr, page: { dataTotal: arr.length, pageTotal: arr.length, size: response.size, page: response.current } }); setMenuDataCopy({ list: arr, page: { dataTotal: arr.length, pageTotal: arr.length, size: response.size, page: response.current } });
重置和过滤逻辑
const onSearch = (params: any) => { if (Object.keys(params).length > 0) { let arr: any = [] var data: any = JSON.parse(JSON.stringify(menuDataCopy)) console.log(data, "datadata") arr = data.list.filter((item: any, index: any) => { return item.styleNumber == params.styleNumber }) console.log(arr) setMenuData({ list: arr, page: { dataTotal: arr.length, pageTotal: arr.length, } }); } else { setMenuData(menuDataCopy) } }
结果展示