gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot call method 'push' of undefined

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:10 24 4
gpt4 key购买 nike

我已经卡在这个错误上好几天了,有哪位好心人能破译这个错误吗?警报显示所需的正确数据,但不知何故 push() 方法不起作用。提前致谢!

最佳答案

这不是很容易分辨,但根据注释,您正在调用 push 方法的对象可能是 undefined。而这个对象应该是一个数组

替换这一行:

layer[result['layerId']].push(result);

使用以下代码:

if("undefined" != typeof layer[result['layerId']]) {
layer[result['layerId']].push(result);
}
else {
layer[result['layerId']] = new Array();
layer[result['layerId']].push(result);
}

让我知道它是否有效。

关于javascript - 未捕获的类型错误 : Cannot call method 'push' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15673932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com