无法在 reactjs 中的 return 内读取 null 的 属性 'category'

Cannot read property 'category' of null within return in reactjs

我从 json 文件中获取一些数据,并使用 .map 将这些点放在 reactjs 中的 google 地图上,一切正常。但是对象中的一些项目没有任何值,如果调用它们,它们会抛出:'TypeError: Cannot read 属性 'category' of null'。我不应该只能在 return:

中做类似下面的事情吗?
{ marker.outcome_status.category && <p>Outcome: {marker.outcome_status.category} ({marker.outcome_status.date})</p> }

由于您有 2 个嵌套级别,因此您需要检查还有 marker.outcome_status

{ 
  marker.outcome_status
  && marker.outcome_status.category
  && <p>Outcome: {marker.outcome_status.category} ({marker.outcome_status.date})</p> }