我有一些像这样的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"
}]
如何创建一个看起来像这样的多维数组。我需要将第一个和第三个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中看到该数组。