无法解析数据表行数据中的 html 标记



我在DataTables的每个单元格的单个元素中获取HTML标签。我也想解析 HTML 标签,但到目前为止,无法这样做。

我已经尝试过html-react-parser,但它正在将它们解析为一个数组。

import Parse from "html-react-parser";
<Table className={classes.table}>
        <TableHead>
          <TableRow>
            {/* <TableCell>Dessert (100g serving)</TableCell>
            <TableCell align="right">Calories</TableCell>
            <TableCell align="right">Fat (g)</TableCell>
            <TableCell align="right">Carbs (g)</TableCell>
            <TableCell align="right">Protein (g)</TableCell> */}
            {props.tableData.HeadingData.map(el=>{
              return <TableCell align="right">{el}</TableCell>
            })}
          </TableRow>
        </TableHead>
        <TableBody>
          {rows.map(row => (
            <TableRow>
              {/* <TableCell align="right">{row}</TableCell> */}
              {row.map(el=>{
                console.log(Parse(el));
                return <TableCell align="right">{Parse(el)}</TableCell>
              })}
            </TableRow>
          ))}
        </TableBody>
      </Table>
"content":{
                "Title": "List Title",
                "HeadingData" :["Name", "Company", "City", "State"],
                "RowData" :[
                    ["Joe James", "Test Corp<br/>TestCorp", "Yonkers", "NY"],
                    ["John Walsh", "Test Corp", "Hartford", 1989],
                    ["Bob Herm", "Test Corp", "Tampa", "FL"],
                    ["James Houston", "Test Corp", "Dallas", "TX"],
                ]
            },

以上是表格数据,如果您看到公司有html标签"Test Corp
测试公司"。

我无法解析它,因为它返回一个数组。

我找到了解决方案。通过在通过 html-react-parser 解析之前将每个单元格元素转换为字符串来解决。

最新更新