我有table
,它是按x
价值和y
价值定位的。这些值保存在数据库中。我正在使用 react dnd 来定位这些table
。
我现在要做的是一键保存所有表格位置。为此,我编写了如下代码..
constructor() {
super();
this.state = {
tables: []
}}
saveTables() {
const { state, dispatch, tables } = this.props;
this.state.tables.map((table) => {
const data ={
id: table.id,
x: table.x,
y: table.y,
}
dispatch(Actions.save(this.props.tables.channel, data));
})
}
<button onClick={this.saveTables}>Save</button>
因此,当安装组件时,我将表的所有信息放入this.state.tables
. 因此,对于saveTables()
功能,我想做的是通过映射this.state.tables
调度操作来保存每个表x
的位置。y
但是,它会触发错误TypeError: action is undefined
可以像上面那样做吗?还是有其他方法可以一键保存所有表格数据?
提前致谢..
--编辑完整错误
TypeError: action is undefined[Learn More] app.js:54241:1
routerMiddleware/</</< http://localhost:4000/js/app.js:54241:1
saveTables/< http://localhost:4000/js/app.js:73190:9
map self-hosted
saveTables http://localhost:4000/js/app.js:73184:7
bound saveTables self-hosted
bound bound saveTables self-hosted
ReactErrorUtils.invokeGuardedCallback http://localhost:4000/js/app.js:45316:7
executeDispatch http://localhost:4000/js/app.js:39166:5
executeDispatchesInOrder http://localhost:4000/js/app.js:39189:5
executeDispatchesAndRelease http://localhost:4000/js/app.js:38581:5
executeDispatchesAndReleaseTopLevel http://localhost:4000/js/app.js:38592:10
forEach self-hosted
forEachAccumulated http://localhost:4000/js/app.js:50930:5
EventPluginHub.processEventQueue http://localhost:4000/js/app.js:38795:7
runEventQueueInBatch http://localhost:4000/js/app.js:45345:3
ReactEventEmitterMixin.handleTopLevel http://localhost:4000/js/app.js:45356:5
handleTopLevelImpl http://localhost:4000/js/app.js:45438:5
TransactionImpl.perform http://localhost:4000/js/app.js:50185:13
ReactDefaultBatchingStrategy.batchedUpdates http://localhost:4000/js/app.js:45084:14
batchedUpdates http://localhost:4000/js/app.js:48223:10
ReactEventListener.dispatchEvent http://localhost:4000/js/app.js:45513:7
bound