gpt4 book ai didi

javascript - 传递多个参数 onChangeText 输入元素函数 - React Native

转载 作者:行者123 更新时间:2023-12-03 13:58:18 25 4
gpt4 key购买 nike

我有多个 Input 元素,每次用户在这些输入中键入内容时,我都会调用 handleChange() 函数,该函数应该告诉用户写了什么以及他输入了哪个输入英寸。

这就是我所做的:

handleChange(text, name) {
console.log("test: "text+" "+name);
}

//http://facebook.github.io/react-native/releases/0.23/docs/textinput.html
for (var p = 0; p < 20; p++){
products.push (<TextInput name={p} onChangeText={(text, name) => this.handleChange(text, name)}></TextInput> );
}

handleChange 函数中的 console.log 正确显示用户编写的文本,但未正确显示 name 变量,结果 未定义

最佳答案

name 应该是什么?您所做的就是将 name 设置为整数,但有一种方法可以使其发挥作用:

handleChange(text, name) {
console.log("test: "text+" "+name);
}

//http://facebook.github.io/react-native/releases/0.23/docs/textinput.html
for (let p = 0; p < 20; p++){
products.push (<TextInput onChangeText={(text) => this.handleChange(text, p)}></TextInput> );
}

关于javascript - 传递多个参数 onChangeText 输入元素函数 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41467700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com