如何从动态创建的文本输入框中访问值。例如,平面列表创建3个文本输入框,然后在单击按钮时,我们验证哪一个已添加,哪一个未添加。如何管理多个状态数组。目前我是这样做的。
const data = [1,2];
constructor(props) {
super(props);
this.state = {
Textdata:[],
};
}
SubmitButton(){
//how to access those text input values and add to array
}
<FlatList
data={data}
renderItem={this.renderItem}
keyExtractor={(item, index) => item}
/>
renderItem = ({ item, index }) => {
return (
<View>
<Item
floatingLabel
style={styles.InputBoxStyle}
>
<Label>First Name</Label>
<Input
/>
</Item>
<Item
floatingLabel
style={styles.InputBoxStyle}>
<Label>Last Name</Label>
<Input
/>
</Item>
<Button rounded
onPress={this.SubmitButton}>
<Text>Submit</Text>
</Button>
</View>
);
};
newArray[value] = index;
-> 更改为newArray[index] = value;
并且:在onValueChange
函数中交换参数 ->onValueChange(index: number, value: string)
- Nikolay Tomitov