对于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“。
我无法解析它,因为它返回一个数组。
发布于 2019-04-11 14:44:11
我找到了解决方案。通过在通过html-react-parser解析之前将每个单元格元素转换为字符串来解决。
https://stackoverflow.com/questions/55625890
复制相似问题