0

143 個の他のオブジェクトの配列を含むマルチレベルの JSON オブジェクトがあります。

このオブジェクトで console.log(obj) を実行すると、次のように表示されます。

0: Object
  ActFTEs: 0.00
  Actual: 11111
  Bud_Month: "October"
  FY_CD: 2013
  Mission_Name: "RST"
__proto__: Object
1: Object
  ActFTEs: 0.00
  Actual: 10000
  Bud_Month: "FY Total"
  FY_CD: 2013
  Mission_Name: "RST"

など.... 143 個のオブジェクトすべてを通じて。ただし、名前と値のペア Mission_Name:"RST" は、最初のn 個のオブジェクトでのみ一般的です。

たとえば、obj 43 には以下が含まれます。

43: Object
   ActFTEs: 0.00
   Actual: 10000
   Bud_Month: "FY Total"
   FY_CD: 2013
   Mission_Name: "VAO"

次の関数を作成しましたが、「Bud_Month」に関連する名前と値のペアの 143 個の値の全範囲が返されます。

function get_dataArray() {
 var arr = [];
 var i= 0;
 for (i=0;i<jsonobj.row.length;i++) {   
    if (jsonobj.row[i][name]="RST") {
         arr[i] = jsonobj.row[i]["Bud_Month"];
    }    
 } 
 console.log(arr);
 return arr;
}

これは以下を返します:

["October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "FY Total", "October", "November", "December", "January", "February", "March", "April", "May", "June", "July", "August", "September", "November", "October", "FY Total", "December", "January", "February", "March", "April", "May", "June"…]

Mission_Name:"RST" の名前と値のペアを含むオブジェクトでのみ "Bud_Month" の値を返す方法について誰かアドバイスはありますか?

4

1 に答える 1

0
if (jsonobj.row[i][name]="HST") {
     arr[i] = jsonobj.row[i]["Bud_Month"];
}   

おそらく次のようになります。

if (jsonobj.row[i][name]=="RST") {
     arr[i] = jsonobj.row[i]["Bud_Month"];
}   
于 2013-02-14T05:12:53.977 に答える