React Native 使用Image標籤是對uri進行判空

判斷對象不爲空的方法:

 /*判斷對象爲空*/
    isEmpty(obj){
        if(typeof (obj) != 'number' && (!obj || obj == null || obj == ' ' || obj == undefined || typeof (obj) == 'undefined')){
            return true;
        }
        return false;
    },
    /*判斷對象不爲空*/
    isNotEmpty(obj){
        if(!this.isEmpty(obj)){
            return true;
        }
        return false;
}

使用Image標籤時判斷:

{ Filter.isNotEmpty(this.props.upgradeObj) && Filter.isNotEmpty(this.props.upgradeObj.imgUrlPath) ?
       <TouchableOpacity activeOpacity={1}
           onPress={() => this.onPressBannerConfig(this.props.upgradeObj)}>
      <Image  source={{uri: this.props.upgradeObj.imgUrlPath}}
           style={{width: deviceWidth * 0.76, height: deviceWidth * 0.84 ,resizeMode: Image.resizeMode.contain}}/>
      </TouchableOpacity> : null
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章