React native 更新平面列表中的单个项目

React native 更新平面列表中的单个项目,react-native,react-native-android,react-native-flatlist,React Native,React Native Android,React Native Flatlist,嘿,伙计们,我需要更新平面列表数据中的单个项目。我想清点购物车里的物品。 当我点击+或-时,它没有变化。但当我使用平面列表的extradata道具时,它在所有计数中都会发生变化 class Cart extends Component { state: { count:0 } render() { const cartcount = <View style= {{height:40,

嘿,伙计们,我需要更新平面列表数据中的单个项目。我想清点购物车里的物品。 当我点击+或-时,它没有变化。但当我使用平面列表的extradata道具时,它在所有计数中都会发生变化

    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>
    />
类购物车扩展组件{
声明:
{
计数:0
}
render(){
常数cartcount=
{this.setState({
计数:this.state.count-1
})}}>
-{this.state.count>=0&&this.state.count!==0?this.state.count:1}
{this.setState({count:this.state.count+1}}}>+
;
返回(
{cartcount}
/>

您是说,在单击+或-,计数(状态变量)不会得到更新?状态正在更新,但当我单击它时,使用extradata呈现所有列表,并在所有列表项中计数+1,但当我无法使用extradata时,它无法执行任何操作