判断对象不为空的方法:
/*判断对象为空*/
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
}