判斷對象不爲空的方法:
/*判斷對象爲空*/
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
}