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
}

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