AtInputNumber组建直接输入没法通过setState更改value



  • 一个列表渲染,每项都可以更改value,直接输入,没法更改value,value值就是输入的值,通过setState更改没反应。
    const shoplistview = shopCarList.map((item,index)=>{
    var num = item.num;
    return <View className="shopCarBox">
    <CheckboxGroup className='checkboxgroup' onChange={this.checkboxChange.bind(this,item,index)}>
    <label class="checkbox">
    <Checkbox value={item.value} checked={item.checked}/>

                </label>
                <Image src={item.goods.cover} onClick={this.goGoodInfo.bind(this,item)}></Image>
                  <View className='msg_right' onClick={this.goGoodInfo.bind(this,item)}>
                    <View>{item.goods.name}</View>
                    <View className='dec'>默认</View>
                    <View className='money'>
    					¥{item.goods.discountPrice ? item.goods.discountPrice : item.goods.price}
    				</View>  
    				
                  </View>
              </CheckboxGroup>
              <AtInputNumber
                className='atinput'
                min={1}
                step={1}
    			value={item.num}
    			width={50}
    			onChange={this.handleChange.bind(this,item,index)}
              />
    			<Image src={delIcon} className="del_icon" onClick={this.delShopCar.bind(this,item)}></Image>
    			
              </View> 
        })
    

    handleChange(item,index,value){//修改购物车商品数量
    console.log('item:',item,',index:',index,',value:',value)

    	let loading = Taro.showLoading({
    		title: '修改中',
    		mask: true,
    	})
    	let that = this;
    	let {userInfo} = this.props.userInfo;
    	let {shopCarList} = this.state;
    	let num = shopCarList[index].num;
    	console.log('num:',num)
    	let params = {
    		userId: userInfo.id,
    		goodsId: item.goods.id,
    		num: value,
    	}
       	Taro.request({
    		url:config.url.shop_server+'/api/shopping/cart/updateGoodsNum',
    		header: {
    			'content-type':'application/x-www-form-urlencoded'
    		},
    		data: params,
    		method:'POST'
        })
        .then(res => {
        	Taro.hideLoading();
            console.log('handleChange-res:',res)
            if(res.data.code == 1){
            	shopCarList[index].num = Number(value);
            	console.log('shopCarList:',shopCarList)
            	that.setState({
            		shopCarList,
            	},() => {
            		that.setTotalPriceAndState();
            	})
            }else{
    			console.log('num1:',shopCarList[index].num)
    			shopCarList[index].num = Number(num);
    			that.setState({
            		shopCarList,
            	},() => {
    				console.log('shopCarList:',this.state.shopCarList)
            		that.setTotalPriceAndState();
            	})
          	 	Taro.showToast({
    				title: res.data.message,
    				icon: 'none'
    			});
    			
            }
        })
    }


  • 还有一个思路,怎么禁止直接输入,只允许通过点击+-更改value


登录后回复