美文网首页
React Native 使用Image标签是对uri进行判空

React Native 使用Image标签是对uri进行判空

作者: Volon | 来源:发表于2019-06-21 08:43 被阅读0次

判断对象不为空的方法:

 /*判断对象为空*/
    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
}

相关文章

网友评论

      本文标题:React Native 使用Image标签是对uri进行判空

      本文链接:https://www.haomeiwen.com/subject/hvnjqctx.html