【发布时间】:2018-01-22 23:26:45
【问题描述】:
我有一个组件,它简单地呈现一行数据,并且每一行都有一个删除按钮。单击删除应该只是使用过滤器更改状态以过滤掉单击的行。为什么会出现以下错误。
我尝试使用 console.log 进行调试,我确实得到了正确的 row.id 和 rowId 来过滤,但我的行状态没有被重新分配。
interface TableSampleProps {
rows: any[];
}
interface TableSampleState {
rows: any[];
}
export class TableSample extends React.Component<TableSampleProps, TableSampleState> {
constructor(props: TableSampleProps) {
super(props);
this.state = {
rows: this.props.rows.concat(),
};
}
public render() {
return <MyTable rows={this.state.rows} onDeleteRow={this.deleteRow} />;
}
private deleteRow = (rowId: number) => {
// console.log(rowId);
// this.state.rows.filter((row) => console.log(row.id !== rowId));
this.setState = {
rows: this.state.rows.filter((row) => row.id !== rowId),
};
}
}
] ./src/ts/components/table-sample-tool.tsx [0] (57,13) 中的错误:错误 TS2322: 输入'{行:任何[]; }' 不可分配给类型 '{ (f: (prevState: TableSample State, props: TableSampleProps) => 挑选, ...'。 [0] 对象字面量只能指定 已知属性,并且 'rows' 不存在于类型 '{ (f: (prevS tate: TableSampleState, props: TableSampleProps) => 挑选, ...'。 [0] 子 html-webpack-plugin 用于 "index.html": [0] 块 {0} index.html 542 kB [entry] [0]
+ 4 个隐藏模块 [0] webpack:编译失败。
【问题讨论】:
标签: reactjs typescript