I'm using react native expo.I have a react native picker which have the data that i have fetched from my back end api and the whole set of data is stored in an array(properties) inside the state. This is a screenshot of my data fetched to Select Property picker or drop down
I need to get the a particular data inside the "Type" array that belongs to the _id of the property which I select from the Property dropdown.I need that data(tname) to be fetched to the Select Type drop down.I need this do be done using React Native without accessing the backend for a second time(in front end). This is my code inside the render for drop down
<View style={{margin: 20, flexDirection: 'row', flex: 1}}>
{/*PROPERTY....................................................*/}
<View style={{padding: '10px'}}>
<Picker style={styles.picker} selectedValue={this.state.pickerProperty}
onValueChange={(itemValue, itemIndex) => this.getPropertyById(itemValue)}>
<Picker.Item label="Select Property" value=""/>
{this.state.properties.map((item, key) => (
<Picker.Item label={item.PropertyName} value={item._id} key={key}/>
))}
</Picker>
{/*{this.getPropertyById()}*/}
</View>
{/*TYPE........................................................*/}
<View style={{padding: 10}}>
<Picker style={styles.picker} selectedValue={this.state.pickerType}
onValueChange={(itemValue, itemIndex) => this.setState({pickerType: itemValue})}>
<Picker.Item label="Select Type" value=""/>
{this.state.propById.map((item, key) => (
<Picker.Item label={item.tname} value={item.tname} key={key}/>
))}
</Picker>
<Text>{this.state.pickerType}</Text>
</View>
</View>
I need to write my code inside this function
getPropertyById=(itemValue)=> { //Need the code here
}