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 的第一个和第三个 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