【问题标题】:How to disabled button on array response value in react native如何在本机反应中禁用数组响应值上的按钮
【发布时间】:2020-02-25 10:58:24
【问题描述】:

在我的代码中。 IdentificationType 是一个包含所有值的数组。现在我必须禁用下面的按钮 CustomButton : 条件如果是强制性的:true 和 uploadStatus: false。

我尝试了一些东西,但没有得到结果。

disabled={(!this.state.IdentificationType.uploadStatus == false)&&(this.state.IdentificationType.mandatory===true)  }

const {IdentificationType}= this.state;
IdentificationType (3) [{…}, {…}, {…}]
0:
idType: "POID"
name: "Proof Identity"
description: "Upload your identity proof"
mandatory: true
eligibleDocumentList: (3) [{…}, {…}, {…}]
__typename: "IdentificationTypes"
doctype: (3) [{…}, {…}, {…}]
selectValue: "passport"
issueDate: "25/02/2020"
expDate: "25/02/2020"
idNumber: ""
place: ""
image: ""
uploadStatus: false
displayThumbnail: false
fileName: ""
__proto__: Object
1: {idType: "addressProof", name: "Address Proof", description: "Upload your address proof", mandatory: false, eligibleDocumentList: Array(3), …}
2: {idType: "ageProof", name: "Age Proof", description: "Upload your age proof", mandatory: false, eligibleDocumentList: Array(3), …}
length: 3


<View style={{ alignSelf: 'center', paddingTop: 20, position: 'absolute', bottom: 10, zIndex: 10 }}>
                    <CustomButton backgroundColor={parentStyle[appliedTheme] ? parentStyle[appliedTheme][appliedMode].primaryButtonColor : null}
                        width={deviceWidth - 30} label={'Save & Proceed'} height={60} labelFontSize={hp('2.5%')}
                        disabled={true}
                        onPress={() => this.nextStep()} >
                    </CustomButton>
                </View>

【问题讨论】:

  • 用map函数编写完整代码。我需要知道你是如何从数组中访问数据的。
  • IdentificationType 是一个数组,我在上面的代码中写了什么值,在我的代码中,有一些输入字段和按钮,我必须在该代码上禁用该按钮,我该怎么做,请建议

标签: javascript reactjs react-native ecmascript-6


【解决方案1】:
{/* before return */}
let {IdentificationType} = this.state;
{/* in render method */}
{IdentificationType && IdentificationType.map(function(value){
    <CustomButton disabled={value.mandatory === true && value.uploadStatus === false ? true : false}></CustomButton>
})}

【讨论】:

  • 感谢您的宝贵时间,但如果我使用此按钮,getitng 就会消失
猜你喜欢
  • 2020-06-09
  • 1970-01-01
  • 2018-06-03
  • 2018-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
相关资源
最近更新 更多