我为 TextInput 创建了公共类并多次使用它,但它的事件句柄使用相同的方法。我想在 textInput 中填充数据后处理数组数据。
此处添加了多个 textField 和单个handleAddMore
. 如何识别哪个 textInput 调用了handleAddMore
.
textField 组件根据数组数据动态添加。现在,当用户编辑 textInput 时,我想识别特定索引上的 textInput 和更新的数组文本。
let addMoreCompView = this.state.dataAddMore.map((data ,index) =>{
return(
<View style ={[styles.commonMargin ,{flexDirection : 'row',marginTop : 2 , height : 40, backgroundColor : Globle.COLOR.INPUTCOLOR}]}>
<View style = {{height : '100%' , width : '80%' , justifyContent: 'center' ,alignItems: 'flex-start', flexDirection : 'column'}}>
<TextInput style = {{fontFamily: 'Gotham-Light',fontSize : 14 ,color: Globle.COLOR.BACKCOLOR , paddingLeft : 20}}
underlineColorAndroid = "transparent"
placeholder = 'Please enter emailID.'
placeholderTextColor = 'black'
autoCapitalize = "none"
keyboardType = "email-address"
onSubmitEditing ={Keyboard.dismiss}
onChangeText = {this.handleAddMore}
autoCorrect = {false}/>
</View>
<TouchableOpacity onPress = {() => this.removeMoreComponent(data.key)} style = {{height : '90%' , width : '20%' , alignItems: 'flex-end', justifyContent: 'center'}}>
<Image style = {{width : 9 , height : 10 , marginRight : 20}} source = {require('./Images/cancelMore.png')}/>
</TouchableOpacity>
</View>
)
});
在这里,我想确定哪个TextInput
调用了这个方法。
在这里,我想要 textField 的文本和索引。
handleAddMore = (text) =>{
// Here I want to text and index of textField.
}