react-native - 更新 Flatlist 中的单个项目
问题描述
嘿伙计们,我需要更新 FlatList 数据中的单个项目。我想计算购物车中的物品。当我单击 + 或 - 时,它没有任何变化。但是当我使用平面列表的额外数据道具时,它的所有计数都发生了变化..
class Cart extends Component {
state:
{
count:0
}
render() {
const cartcount = <View style= {{height:40,
flexDirection:'row',
justifyContent:'space-around'}}>
<TouchableOpacity onPress={()=>
{this.setState({
count: this.state.count-1
})}}>
<Text>-</Text></TouchableOpacity><Text
> { this.state.count >=0 && this.state.count !== 0 ? this.state.count: 1 }</Text>
<TouchableOpacity onPress={()=>
{this.setState({ count: this.state.count+1})}}><Text>+</Text></TouchableOpacity>
</View>;
return (
<FlatList data={this.state.cart}
renderItem={({item,index}) =>
<View>{ cartcount }</View>
/>
解决方案
推荐阅读
- r - 随机生成具有指定聚类系数的网络
- c++ - 转换罗马数字阿拉伯形式的基本程序?
- algorithm - Search first appearence in matrix under time complexity demands
- ios - 我怎么知道 Instagram 按钮已被选中?
- label - Vue-Chartjs onComplete 自定义标签 - 防止闪烁
- android - React Native api 在物理 Android 设备上不起作用(错误:网络错误)
- powershell - 使用 -eq 或 -ne 在 Powershell 中检测变音符号
- php - Telegram Inline Bot 不会显示
- react-native - React Native 显示警告“不再需要在 Animated 组件的 ref 上调用 `getNode()`。”
- android - 在 onActivityResult 中收到“content://”Uri 后从 MediaStore 获取 PDF?