1

私はそのようないくつかのjsonを持っています

[{
  "merchantcontract":"Kevin\u0027s Radiator and Auto Repair 1916.01",
  "merchantcontractid":"60dccd9d-1114-e111-8a4f-00155d010302",
  "smi_transactiondate":"\/Date(1332918000000)\/",
  "smi_glamount2":2.1800,
  "smi_transactionclass":180870001,
  "smi_transactionclassname":"Residual Agent Commission",
  "smi_contractprodcutidname":"Traditional",
  "smi_agentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5",
  "smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
 },{
  "merchantcontract":"Kevin\u0027s Radiator and Auto Repair 1916.01",
  "merchantcontractid":"60dccd9d-1114-e111-8a4f-00155d010302",
  "smi_transactiondate":"\/Date(1333004400000)\/",
  "smi_glamount2":0.9700,
  "smi_transactionclass":180870001,
  "smi_transactionclassname":"Commercial Agent Commission",
  "smi_contractprodcutidname":"Traditional",
  "smi_agentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5",
  "smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
 },{
  "merchantcontract":"Kevin\u0027s Radiator and Auto Repair 1916.01",
  "merchantcontractid":"60dccd9d-1114-e111-8a4f-00155d010302",
  "smi_transactiondate":"\/Date(1333090800000)\/",
  "smi_glamount2":1.6200,
  "smi_transactionclass":180870001,
  "smi_transactionclassname":"Residual Agent Commission",
  "smi_contractprodcutidname":"Traditional",
  "smi_agentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5",
  "smi_primaryagentid":"1d3f44ee-afc3-e011-addf-a4badb1ddef5"
}]

このような多次元配列を作成するにはどうすればよいですか。Residual Agent Commission である 1 番目と 3 番目の smi_glamount2 を一緒に追加して配列に追加する必要があります

merchantcontractarray[Kevin\u0027s Radiator and Auto Repair 1916.01][merchantcontract]
merchantcontractarray[Kevin\u0027s Radiator and Auto Repair 1916.01][Residual Agent Commission]
merchantcontractarray[Kevin\u0027s Radiator and Auto Repair 1916.01][Residual Agent Commission][smi_glamount2 + smi_glamount2]
merchantcontractarray[Kevin\u0027s Radiator and Auto Repair 1916.01][Commercial Agent Commission][[0.9700]

私はこれを使ってみました

$.each(data, function(i, field) {
    if (currentid == field.merchantcontract) {
        if (currentclassname == field.smi_transactionclass) {
            if (field.smi_transactionclass == '180870001') {
                residual = residual + field.smi_glamount2;
            } else if (field.smi_transactionclass == '180870000') {
                upfront = upfront + field.smi_glamount2;
            }
        } else {
            currentclassname = field.smi_transactionclass;
            if ($.inArray(currentclassname, smi_transactionclass) == -1) {
                smi_transactionclass[i].push(currentclassname);
            }
        }
    } else {
        currentid = field.merchantcontract;
        if ($.inArray(currentid, merchantcontract[1]) == -1) {
            merchantcontract[i].push(currentid);
        }
        //console.log(currentid);
    }
});​

そんな運がなければ

助けていただければ幸いです。jsfiddle を作成しました。console.log で配列を確認するだけで十分です。

http://jsfiddle.net/qs2nR/

4

0 に答える 0