Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对二级儿童使用传球道具做出反应_Javascript_Reactjs_Children_Prop - Fatal编程技术网

Javascript 对二级儿童使用传球道具做出反应

Javascript 对二级儿童使用传球道具做出反应,javascript,reactjs,children,prop,Javascript,Reactjs,Children,Prop,我面临着在React中编码时传递道具的问题。是的,我以前见过这个问题,但这次是第二级儿童组件,事情有点奇怪。我的代码(沿途注释): 类EditForm扩展了React.Component{ handleSubmit=(事件,idx)=>{ event=>event.preventDefault(); postData('/',{idx:idx}) .then(data=>{if(data.success){window.location='/';}}); console.log(idx);//从

我面临着在React中编码时传递道具的问题。是的,我以前见过这个问题,但这次是第二级儿童组件,事情有点奇怪。我的代码(沿途注释):

类EditForm扩展了React.Component{ handleSubmit=(事件,idx)=>{ event=>event.preventDefault(); postData('/',{idx:idx}) .then(data=>{if(data.success){window.location='/';}}); console.log(idx);//从此处打印的结果 } render(){ 返回( this.handleSubmit(idx)}//输出1 onFinish={()=>this.handleSubmit(this.props.idx)}//输出2 > ); } } 类UpdateModel扩展了React.Component{ render(){ 返回( //值仍然没有定义 ); } } 产出:

//1
useForm.js:766 ReferenceError:idx未定义
// 2
未定义
有人能解释一下为什么我不能连续两次通过道具吗?事实上,这些值在UpdateModel中时仍然有效,但之后不知何故消失了


提前感谢。

您应该将事件对象传递给您的处理程序:

类EditForm扩展了React.Component{ handleSubmit=(事件,idx)=>{ event=>event.preventDefault(); postData('/',{idx:idx}) .then(data=>{if(data.success){window.location='/';}}); console.log(idx);//从此处打印的结果 } render(){ 返回( this.handleSubmit(event,idx)}//输出1 onFinish={(event)=>this.handleSubmit(event,this.props.idx)}//输出2 > ); } } 类UpdateModel扩展了React.Component{ render(){ 返回( //值仍然没有定义 ); } }
您应该将事件对象传递给处理程序:

类EditForm扩展了React.Component{ handleSubmit=(事件,idx)=>{ event=>event.preventDefault(); postData('/',{idx:idx}) .then(data=>{if(data.success){window.location='/';}}); console.log(idx);//从此处打印的结果 } render(){ 返回( this.handleSubmit(event,idx)}//输出1 onFinish={(event)=>this.handleSubmit(event,this.props.idx)}//输出2 > ); } } 类UpdateModel扩展了React.Component{ render(){ 返回( //值仍然没有定义 ); } }
类EditForm扩展了React.Component{
建造师(道具){
超级(道具);
}
// ...
}
类UpdateModel扩展了React.Component{
建造师(道具){
超级(道具);
}
// ...
}
// 
// 
类EditForm扩展了React.Component{
建造师(道具){
超级(道具);
}
// ...
}
类UpdateModel扩展了React.Component{
建造师(道具){
超级(道具);
}
// ...
}
// 
//