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>
); }
&#13;
<ListView
dataSource={this.state.userDataSource}
renderRow={this.renderRow.bind(this)}
/>
&#13;
i want to access the rate highlighted in yellow
我是新来的反应原生,所以我想访问一个对象数组,只获得一个以黄色突出显示的特定值,我不知道我该怎么做?
谢谢
答案 0 :(得分:2)
ListView为deprecated,建议您改用FlatList。其中一个原因是因为它的“更易于使用API”
如果您的userDataSource
对象如下所示:
[
{MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"},
{MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"},
{MaxAmt:"value",MinAmt:"value",Rate:"value",RecieverID:"value"}
]
您的renderItem
函数(而非renderRow
)应如下所示:
renderItem({item}){
return(
<View style={styles.row}>
<Text style={styles.rowText}> Rate {item.Rate}</Text>
</View>
);
}
您可以像这样创建列表:
<FlatList
data=this.state.userDataSource
renderItem={({item}) => this.renderItem(item)}
/>