Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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
React native 通过onPress传递数据不需要';不允许在函数中正确传递参数_React Native - Fatal编程技术网

React native 通过onPress传递数据不需要';不允许在函数中正确传递参数

React native 通过onPress传递数据不需要';不允许在函数中正确传递参数,react-native,React Native,我正在尝试将数据传递到react native中的特定页面。每当我按下按钮进入该页面时,在特定事件的特定页面上应该调用的函数会在我按下按钮时提前调用 add=(ss)=>{ const textInput=this.state.textInput.concat(textInput) this.setState({textInput}) 控制台日志(ss) } render(){ 返回( 地址:{this.state.Address} 正确绑定函数,应按如下方式编写: onPress ={()

我正在尝试将数据传递到react native中的特定页面。每当我按下按钮进入该页面时,在特定事件的特定页面上应该调用的函数会在我按下按钮时提前调用

add=(ss)=>{
const textInput=this.state.textInput.concat(textInput)
this.setState({textInput})
控制台日志(ss)
}
render(){
返回(
地址:{this.state.Address}

正确绑定函数,应按如下方式编写:

onPress ={() => this.add('dssda')}

如果您不想传递参数,您应该编写
onPress={this.add}
那么该函数只会在onPress事件上正确调用,因为它被正确绑定在那里,使用的参数数量与
onPress
回调中的参数数量相同,即没有参数。

正确绑定函数,您应该按照以下方式编写它:

onPress ={() => this.add('dssda')}

如果您不想传递参数,并且您已经编写了
onPress={this.add}
,那么该函数将正确调用onPress事件,因为它在那里被正确绑定,具有与
onPress
回调相同数量的参数,即没有参数。

on Press应该被绑定

onPress ={() => this.add(data)}
在方法中传递给ss变量

add=(ss)=> {
     const textInput = this.state.textInput.concat(TextInput)
     this.setState({ textInput })

    console.log(ss)
  }

希望这一切顺利。谢谢!

在印刷机上应该装订好

onPress ={() => this.add(data)}
在方法中传递给ss变量

add=(ss)=> {
     const textInput = this.state.textInput.concat(TextInput)
     this.setState({ textInput })

    console.log(ss)
  }

希望这可以正常工作。谢谢!

记住绑定你的函数。你可以像这样在类组件的构造函数中绑定事件:

 constructor(props) {
    super(props);
    this.state = {
    };
    this.add = this.add.bind(this);
}

记住绑定你的函数。你可以像这样在类组件的构造函数中绑定事件:

 constructor(props) {
    super(props);
    this.state = {
    };
    this.add = this.add.bind(this);
}

我认为您提供了不完整的代码..还可以尝试onPress={()=>this.add('dssda')}我认为您提供了不完整的代码..还可以尝试onPress={()=>this.add('dssda')}