我在单个元素中为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
TestCorp”。
我无法解析它,因为它正在返回一个数组。
答案 0 :(得分:0)
我找到了解决方案。 通过在通过html-react-parser进行解析之前将每个单元格元素转换为字符串来解决。