我正在尝试使用redux逻辑更新react表中的一行。以下是我在组件中调用的操作。
handleEdit = () => {
this.setState({
id: this.state.id,
name: this.state.name,
uid: this.state.uid,
serial: this.state.serial,
name: this.state.name,
status: this.state.status,
nodeType: this.state.nodeType
});
this.props.editCard({
id: this.state.id,
name: this.state.name,
uid: this.state.uid,
serial: this.state.serial,
name: this.state.name,
status: this.state.status,
nodeType: this.state.nodeType
});
};
这就是我编写减速器的方式
[types.CARD_UPLOADER_EDIT_SUCCESS]: (state, { payload }) => {
console.log("payload", payload);
const index =
state.data && state.data.findIndex(i => i.id === payload.id);
if (index != -1 && state.data) {
state.data.splice(index, 1, payload);
}
return { ...state, editSuccess: true };
},
尽管服务已被触发,而不是更新,但新条目将添加到数据库中。有人可以帮我解决这个问题吗?