我目前正在搞乱多维数组,以存储一些涉及多个连接表和每个内部多个字段的信息。我正在使用jQuery.ajax()抓取数据并使用.each输出它,所有这些工作正常,但现在我正在尝试设置数组,Chrome控制台显示未定义的值,当我从我可以看到应该设置它们。设置的唯一一个是循环的最后一次传递。
这就是我在循环中设置数组的原因:
gAuthrequests[gAuthrqcount][1] = [];
gAuthrequests[gAuthrqcount][1][i] = [];
gAuthrequests[gAuthrqcount][1][i][0] = val.KRANE_REQUEST_DETAILS_ID;
gAuthrequests[gAuthrqcount][1][i][1] = comments;
gAuthrequests[gAuthrqcount][1][i][2] = 0;
i++;
我知道循环有效,因为它输出正常,我也在一点使用console.log来跟踪这些行的数组进度,一切看起来都很好,这是输出:
KRID: (96) Assign Var: gAuthrequests[7][1][0][0]: 63
KRID: (96) Assign Var: gAuthrequests[7][1][0][1]: No comments
KRID: (96) Assign Var: gAuthrequests[7][1][0][2]: 0
KRID: (96) Set var: gAuthrequests[7][1]:
KRID: (96) Set var: gAuthrequests[7][1][1]:
KRID: (96) Assign Var: gAuthrequests[7][1][1][0]: 64
KRID: (96) Assign Var: gAuthrequests[7][1][1][1]: No comments
KRID: (96) Assign Var: gAuthrequests[7][1][1][2]: 0
KRID: (96) Set var: gAuthrequests[7][1]: okr.js:360
KRID: (96) Set var: gAuthrequests[7][1][2]:
KRID: (96) Assign Var: gAuthrequests[7][1][2][0]: 65
KRID: (96) Assign Var: gAuthrequests[7][1][2][1]: No comments
KRID: (96) Assign Var: gAuthrequests[7][1][2][2]: 0
KRID: (96) Set var: gAuthrequests[7][1]:
KRID: (96) Set var: gAuthrequests[7][1][3]:
KRID: (96) Assign Var: gAuthrequests[7][1][3][0]: 66
KRID: (96) Assign Var: gAuthrequests[7][1][3][1]: I want access to this this this this this
KRID: (96) Assign Var: gAuthrequests[7][1][3][2]: 0
在这个例子中,唯一要设置的变量是'gAuthrequests [7] [1] [3]'(66)之前的3是未定义的
答案 0 :(得分:0)
使用对象数组结束:
在第一次循环之前: 'gRQCount = [];'
在第二次循环之前: 'var i = 0;'
循环:
gAuthrequests[gRQCount][i] = {};
gAuthrequests[gRQCount][i].krid = krid;
gAuthrequests[gRQCount][i].krdid = val.KRANE_REQUEST_DETAILS_ID;
gAuthrequests[gRQCount][i].cylinder = cylinderrecid;
gAuthrequests[gRQCount][i].comments = comments;
gAuthrequests[gRQCount][i].status = 0;
i++
为建议elclanrs干杯