我已经为TextInput创建了公共类,并多次使用它,但它的事件处理方法与之相同。我想在填充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.
}
查看GIF:
请检查该参考链接:HTTPS:/ /stackoverflow.com/questions/29280445/reactjs-setstate-with-a-dynamic-key-name –
最好的事情使用redux-form,h ttp://redux-form.com/6.0.0-alpha.4/docs/faq/reactnative.md/ – Sport