首页 > 解决方案 > 无法将 event.target 转换为字符串

问题描述

我有由Ant Design 表中event.target的函数返回的:onRowClick

https://ant.design/components/table/#components-table-demo-colspan-rowspan

它的值是<a>ignissimos aper</a>and 类型object,这意味着它不能被字符串化。

event.target 上没有id属性,所以我不能这样做:

无法将 event.target 转换为字符串

如何将标签转换为字符串?

标签: javascriptreactjstypescriptant-design-pro

解决方案


如果您需要单击的行的数据,请使用 onRowClick 函数的第一个参数,该参数返回数据源的整个行对象。但是,如果您需要单击列的 innerHtml ,您可以这样做:

const onRowClick = (record, index, event) => {
  console.log(record, index, event.target.innerHTML); // event.target.innerHTML is the innerHtml of the clicked column
};

推荐阅读