[英]Display specific value in Flatlist React native
我試圖在 flatlist 中顯示 render 方法中的特定值,但是當我使用 {item.Name[0]} 時,它會顯示所有 Name 值中的所有第一個字母,但我想要整個名字。
return (
<View style={styles.container}>
<FlatList
horizontal
data={this.state.data}
renderItem={({ item,index }) => (
<View style={styles.card_template} >
<View style={styles.text_container}>
<Text style={styles.card_title}>{item.Name[1]}</Text>
<Text style={styles.card_subtitle}>{item.Phone} </Text>
</View>
</View>
)}
/>
</View>
);
}
}```
在markerClick上發出警報后,請執行以下操作:
var temp = this.state.data.filter(x=> x.Name != marker.Name);
temp.unshift(marker);
this.setState({data:temp});
在渲染項上只需使用item.Name
您正在將選定的標記移動到數組中的第一個位置,並且選定的項目將始終位於頂部
我認為如果您遵循解決方案,問題就解決了:
<Text style={styles.card_title}>{item.Name}</Text>
然后嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.