react +antd 报错text.split is not a function

王君墨
2023-12-01
2

1,table列换行报错text.split is not a function

2,如果数组分隔处加上toString

3,代码如下

{
  title: '内容',
  dataIndex: 'content',
  key: 'content',
 render: (text, record) =>{
  let contentStr;
  let br=<br></br>;
  let result=null;
  for(let i=0;i<audits.length;i++){
    let contentStr=audits[i].content;

   // 这里加上toString()
    contentStr=text.split(",");
    contentStr=text.toString().split(",");

    if(contentStr.length<2){
      return text;
    }
    for(let j=0;j<contentStr.length;j++){
      if(j==0){
        result=contentStr[j];
      }else{
        result=<span>{result}{br}{contentStr[j]}</span>;
      }
    }
    return <div>{result}</div>;
  }
},}
 类似资料: