我在项目中使用Lodash
,并且尝试使用get
功能来过滤一些数据以激活按钮以将一些数据保存到端点,但是当我使用get
时在Arroe函数内部,它返回undefined
,然后我在变量分配中使用相同的代码即可正常工作,可以在此StackBlitz中检查错误。有人收到这种错误?预先感谢。
componentDidMount() {
const checkMandatory = tab => {
get(this.state.data, [tab, 'data', 'datosCalculados'], []);
};
const obligatorios = checkMandatory('ingresos');
const obligatorios2 = get(this.state.data, ['ingresos', 'data', 'datosCalculados'], []);
console.log('Obligatorios: ', obligatorios);
console.log('Obligatorios2: ', obligatorios2);
}
return
丢失
代替
const checkMandatory = tab => {
get(this.state.data, [tab, 'data', 'datosCalculados'], []);
};
做
const checkMandatory = tab => {
return get(this.state.data, [tab, 'data', 'datosCalculados'], []);
};
或更好的是:
const checkMandatory = tab => get(this.state.data, [tab, 'data', 'datosCalculados'], []);
导致: