我已經爲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