Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

React Native : How to retrieve data from a State with a nested json array and Map that state to get a particular value with a given id

$
0
0

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
}

Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>