0

我目前正在处理多维数组来存储一些涉及多个连接表和每个表中的多个字段的信息。我正在使用 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 未定义

4

1 回答 1

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 的建议喝彩

于 2012-07-06T01:17:07.773 回答