您好我正在制作api请求,使用FlatList渲染结果,如下所示:
<TouchableOpacity onPress={this._onPressButton}>
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<TouchableOpacity
activeOpacity={0.8}
onPress=this._onPressButton}>
<ListItem
title= {`${item.companyName}`}
subtitle= {`[ ${item.symbol} ] ${item.change}%`}
/>
</TouchableOpacity>
我的目标是访问特定行的数据,假设我创建了一个发出警报的函数:
_onPressButton = () => {
alert('What should search for here?')
};
如何访问item.companyName
?
答案 0 :(得分:0)
你可以:
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<TouchableOpacity
activeOpacity={0.8}
onPress={()=>this._onPressButton(item.companyName)}>
<ListItem
title= {item.companyName}
subtitle= {`[ ${item.symbol} ] ${item.change}%`}
/>
与
_onPressButton = (companyName) => {alert(companyName)};