Reputation: 33
export default class Send extends Component{
constructor(props)
{
super(props);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
userDataSource: ds,
isLoading: true,
PickerValueHolder : '',
amount:'',
RxAmount:'',
exchange:'',
input1:'',
recRate:[{},{},{}]
}
}
fetchUsers(){
fetch('https://trs.php?some parameters')
.then((response) => response.json())
.then((response) => {
console.log(response)
this.setState({
userDataSource: this.state.userDataSource.cloneWithRows(response),
});
});
}
renderRow(user , sectionId, rowId, highlightRow,key){
return(
<View style={styles.row}>
<Text style={styles.rowText}> Rate {user[0].Rate}</Text>
</View>
); }
<ListView
dataSource={this.state.userDataSource}
renderRow={this.renderRow.bind(this)}
/>
i want to access the rate highlighted in yellow
I am new to react native so i want to access an array of objects and get only one particular value which is highlighted in yellow and i don't know how i can do it ?
Thanks
Upvotes: 0
Views: 2342
Reputation: 347
ListView is deprecated and it is encouraged that you use FlatList instead. One reason of which is because of its "easier to use API"
Provided that your userDataSource
object looks like this:
[
{MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"},
{MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"},
{MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"}
]
Your renderItem
function (instead of renderRow
) should look like this:
renderItem({item}){
return(
<View style={styles.row}>
<Text style={styles.rowText}> Rate {item.Rate}</Text>
</View>
);
}
And you can create your list like this:
<FlatList
data=this.state.userDataSource
renderItem={({item}) => this.renderItem(item)}
/>
Upvotes: 3