Here is my exact code:
<Text style={styles.priceText} numberOfLines={2}>
{'$ '+item.right.detail ? item.right.detail.price: ''}{'\n'}{'\n'}
</Text>
So sometimes it's possible that item.right.detail is null or perhaps undefined. This check is not working. I get an error undefined is not an object (evaluating item.right.detail)
I need a way to be able to construct strings of data from object elements where some of those sub objects or values could be null. Obviously I want to do this without crashing!
Do I have to do something crazy like:
private getPrice(item){
var retVal = '$';
if (typeof item !== 'undefined' ) && (item)) {
if (typeof item.right !== 'undefined' ) && (item.right)) {
if (typeof item.right.detail !== 'undefined' ) && (item.right.detail)) {
if (typeof item.right.detail.price !== 'undefined' ) && (item.right.detail.price)) {
retVal = retVal+item.right.detail.price;
}
}
}
}
return retVal;
}