我有一个名为inputErrors的对象数组,需要迭代通过,焦点需要掉落第一个错误。当我在排序数组中的最后一个元素时,代码似乎不起作用。请帮我看看我在这里缺少的东西:
focusOnFirstError = () => {
Object.keys(this.props.inputErrors)
.reduce(
(acc, key) =>
acc.concat([
[
this.props.inputErrors[key].position,
this.props.inputErrors[key].ref
]
]),
[]
)
.sort((a, b) => a[0] - b[0])[0][1]
.focus();
};
示例数据:
inputErrors={
body:{position: "50", ref: "abc"},
callback:{position: "2",ref: "abc"},
more:{position: "1",ref: "abc"},
subject:{position: "49",ref: "abc"}
}