我有一个呈现表行的组件,并且列中的某些日期已经作为全局数据缓存(仅在开始时加载),但是出现以下错误:无法读取行中未定义的属性“名称” 49(检查给定代码段中的注释)。
组件(简体):
const ApplicantRow = observer((props: ApplicantRowProps): React.ReactElement<any> => {
const step = props.sandbox.globalData.cachedSteps.get(props.step.toString())
return (
<div className="row">
<div className="cols">
// ... some cols
<div className="col col-1of7">
<span>{`${props.step}. ${step.name}`}</span> // line 49, step is undefined but why?
</div>
</div>
</div>
)
})
和globalDate类:
class GlobalData implements jc.GlobalData {
@observable public cachedSteps: ObservableMap<string, CachedStep> = observable.map()
// This method is called when steps are fetched from a server and steps are passed as an argument
public setCachedSteps(data: any): void {
runInAction(() => {
const steps = observable.map(data)
this.cachedSteps = steps
})
}
}
我试图在setCachedSteps方法上设置一个断点,以确保在ApplicantRow组件之前调用该断点,这意味着globalDate.cachedSteps中存在数据,这很奇怪为什么返回未定义?