Semantic ui 语义ui反应表。单元格和onClick
我正在使用带有React和的TypeScript。我想替换现有的表呈现,它使用内在的“td”元素呈现表单元格,如下所示:Semantic ui 语义ui反应表。单元格和onClick,semantic-ui,semantic-ui-react,Semantic Ui,Semantic Ui React,我正在使用带有React和的TypeScript。我想替换现有的表呈现,它使用内在的“td”元素呈现表单元格,如下所示: <td className={cssClass} key={idx} onClick={handleClick}>{txt}</td> {txt} 使用Semantic-UI.React Table.Cell元素,如下所示: <Table.Cell className={cssClass} key={idx} onClick={handleC
<td className={cssClass} key={idx} onClick={handleClick}>{txt}</td>
{txt}
使用Semantic-UI.React Table.Cell元素,如下所示:
<Table.Cell className={cssClass} key={idx} onClick={handleClick}>{txt}</Table.Cell>
interface MyTableCellProps extends TableCellProps {
onClick?: React.EventHandler<React.MouseEvent<any>>;
}
const MyTableCell: React.SFC<MyTableCellProps> = (props) => <Table.Cell {...props} />;
interface ExtraTableCellProps {
onClick?: React.EventHandler<React.MouseEvent<any>>;
}
{txt}
问题是强类型的“Table.Cell”元素(其属性由TableCellProps接口确定)上不存在属性“onClick”,因此无法编译代码
我的解决方法是在props子类TableCellProps如下所示的元素中组合Table.Cell元素:
<Table.Cell className={cssClass} key={idx} onClick={handleClick}>{txt}</Table.Cell>
interface MyTableCellProps extends TableCellProps {
onClick?: React.EventHandler<React.MouseEvent<any>>;
}
const MyTableCell: React.SFC<MyTableCellProps> = (props) => <Table.Cell {...props} />;
interface ExtraTableCellProps {
onClick?: React.EventHandler<React.MouseEvent<any>>;
}
接口MyTableCellProps扩展了TableCellProps{
onClick?:React.EventHandler在发布问题时,我忽略了一个非常简单的解决方案,即使用TypeScript spread操作符从强类型界面添加道具,如下所示:
<Table.Cell className={cssClass} key={idx} onClick={handleClick}>{txt}</Table.Cell>
interface MyTableCellProps extends TableCellProps {
onClick?: React.EventHandler<React.MouseEvent<any>>;
}
const MyTableCell: React.SFC<MyTableCellProps> = (props) => <Table.Cell {...props} />;
interface ExtraTableCellProps {
onClick?: React.EventHandler<React.MouseEvent<any>>;
}
interface extractableCellProps{
onClick?:React.EventHandler;
}
然后从render()中:
var myProps:extractableCellprops={
onClick:handleClick
};
返回{txt};
这在不增加React元素嵌套级别的情况下实现了目标
问题是属性“onClick”不存在于
强类型的“Table.Cell”元素(其属性由
TableCellProps接口),因此无法编译代码
你应该使用表格.单元格
,它是固定的,你可以在中按照这项工作
事件返回什么?event.target不包含有关表中单元格的X、Y或位置的任何信息。