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 = [];'

2番目のループの前:'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 に答える