Javascript 使用react native在ListView中增加和减少数量

Javascript 使用react native在ListView中增加和减少数量,javascript,react-native,Javascript,React Native,我正在运行示例项目。我想显示递增和递减值。在我的项目中,不显示增量和减量值。如何更改文本中的值 这是我的密码: constructor(props){ super(props); this.state={ increment:0, decrement:1 } } incrementFunc(){ var countIncrement = this.state.increment thi

我正在运行示例项目。我想显示递增和递减值。在我的项目中,不显示增量和减量值。如何更改文本中的值

这是我的密码:

constructor(props){
      super(props);
      this.state={
         increment:0,
         decrement:1
    }
    }
  incrementFunc(){
        var countIncrement = this.state.increment
        this.setState({
          increment : countIncrement + 1
        },()=>{
          alert(this.state.increment)
        })
      }
      decrementFunc(){

            var countDecrement = this.state.increment

        this.setState({
          decrement : countDecrement- 1,

        },()=>{
          alert(this.state.decrement)
        })
      }

<View style={styles.arrowsView}>
          <TouchableOpacity onPress ={this.incrementFunc.bind(this)}>
          <Image style={styles.arrowStyle} source={require('@images/up-arrow.png')} />
          </TouchableOpacity>
          </View>
          <View style={styles.numberView}>
          <Text style={{fontSize:15, color:'black'}}>{this.state.increment}
          </Text>
          </View>
          <View style={styles.arrowsView}>
          <TouchableOpacity onPress ={this.decrementFunc.bind(this)}>
          <Image style={styles.arrowStyle} source={require('@images/down-arrow.png')} />
          </TouchableOpacity>
          </View>
here is my screenshot:
构造函数(道具){
超级(道具);
这个州={
增量:0,
减量:1
}
}
incrementFunc(){
var countIncrement=this.state.increment
这是我的国家({
增量:countIncrement+1
},()=>{
警报(this.state.increment)
})
}
递减函数(){
var countDecrement=this.state.increment
这是我的国家({
减量:countdecreation-1,
},()=>{
警报(此.状态.减量)
})
}
{this.state.increment}
这是我的截图:

请给出任何建议。谢谢

这是我在项目中提出的解决方案,我所做的

  • 首先->创建了另一个组件,它将帮助我们在列表元素中拥有数量输入功能
  • 其次->此组件需要由list renderRow中的父组件调用,以使此组件在所有行中可见。 并将这个QuantityInput组件类放在您想要使用它的同一个文件中
  • 第三->运行你的应用程序,并有一个这样的外观 请查看附件中的文件

    /*在您的父视图内部列表中使用此组件,以便在列表中输入数量,我也使用了本机基数。如果某些内容丢失,请在您的项目中使用本机基数*/
    {}
    /*数量输入*/
    类QuantityInput扩展了React.Component{
    userProductQty=Array.apply(null,数组(this.props.item.length)).map(Number.prototype.valueOf,1);
    itemPosition=-1;
    建造师(道具){
    超级(道具);
    此.state={
    viewAddToCart:this.props.viewAddToCart,
    项目:this.props.item,
    样式:{flex:1},
    styleTextInput:{backgroundColor:'#ffffff'},
    styleButton:{backgroundColor:'#000000'},
    样式图像:{宽度:12,高度:12},
    是的,
    步长:1,
    初始值:1,
    民:1,,
    最高:100
    }
    }
    upBtnPressed=(数据源,字段名)=>{
    if(dataSource.userQty{
    if(dataSource.userQty{
    如果(!isNaN(文本)){
    item.userQty=text.toString();
    这是我的国家({
    项目:项目
    });
    }否则{
    item.userQty=0;
    这是我的国家({
    项目:项目
    });
    }
    }
    render(){
    返回(
    这个.state.viewAddToCart?
    /*添加到购物车*/
    {this.props.onAddToCart(this.state.item);this.setState({viewAddToCart:false}}}
    >
    {string.addToCart}
    {/**/}
    :
    /*数量文本*/
    {this.downBtnPressed(this.state.item,this.state.item.productId);}>
    -
    {/**/}
    {this.onChangeText(text,this.state.item,this.state.item.productId);this.props.onAddToCart(this.state.item);}/>
    {this.upptnpressed(this.state.item,this.state.item.productId);this.props.onAddToCart(this.props.item);}>
    {/**/}
    +
    );
    }
    }
    const stylesQuantityText=StyleSheet.create({
    包装器:{
    弹性:1,
    背景颜色:“#eeeeee”
    },
    垂直线:{
    flexDirection:'行',
    paddingLeft:0,
    paddingRight:0,
    },
    水平:{
    flexDirection:“行”
    },
    文本输入:{
    背景颜色:“#eeeeee”,
    textAlign:'中心',
    宽度:30,
    边框颜色:“黑色”,
    边框宽度:1,
    身高:26
    },
    按钮:{
    背景颜色:“#dedede”,
    填充:5
    },
    图片:{
    宽度:18,
    身高:18
    },
    按钮文字:{
    自我定位:“中心”
    }
    
    });请编辑您的问题并更好地缩进代码。在当前状态下,很难阅读和理解发生了什么。当我单击incrementFunc()时,该值没有增加。