What I'm trying to achieve is an Array , like this one
infos = [{type: 'phone', val: '2222222'} {type: 'email', val: ' abc@abc.com '}]
Here is state
constructor(props) { super(props); this.state = { rows: [],
So I have two TextInput
<View> <TextInput label='Type'/> <TextInput label='Details'/> </View>
This View can be dynamically added at the click of a button and can also be deleted. Here is my code for the add and remove buttons:
addRow(){ this.state.rows.push(index++) this.setState({ rows: this.state.rows }) } deleteRow(key){ this.state.rows.splice(key, 1) this.setState({ rows: this.state.rows }) } <TouchableOpacity onPress={ this.addRow.bind(this) } > <Text style={{textAlign: 'center',}}>Add</Text> </TouchableOpacity> ... <TouchableOpacity onPress={ () => this.deleteRow(i) } > <Image source={require('./../img/delete.png')} style={{width:32, height: 32 }} /> </TouchableOpacity>
How can I get its value correctly and add it to my Array ? Thanks.
Update
In my TextInput I tried to do this
<TextInput onChangeText={(text)=>{ let cd = this.state.contactDetails; cd[i].val = text ; this.setState({cd}); }} value={this.state.contactDetails[i]} label='Details' />
but I always have an error undefined is not an object (evaluating 'cd[i].val = text')
arrays react-native react-native-android
natsumiyu
source share