对象数组中根据某个属性名的值相同,求某一项的和。
this.initagdata = [{ UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "000000-32767", OperatorName: "超级管理员", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T11:16:27", Qrt: 1, MinAccountTime: "2019-07-16T11:16:12", MaxAccountTime: "2019-07-16T11:16:12", CashPay: 45.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "000000-32767", OperatorName: "超级管理员", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T09:47:20", Qrt: 1, MinAccountTime: "2019-07-16T09:47:08", MaxAccountTime: "2019-07-16T09:47:08", CashPay: 54.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "000000-32767", OperatorName: "超级管理员", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T09:37:33", Qrt: 1, MinAccountTime: "2019-07-16T09:37:19", MaxAccountTime: "2019-07-16T09:37:19", CashPay: 92.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "000000-32767", OperatorName: "超级管理员", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T09:45:41", Qrt: 1, MinAccountTime: "2016-07-16T09:45:27", MaxAccountTime: "2019-11-16T09:45:27", CashPay: 45.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "000000-32767", OperatorName: "超级管理员", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T11:11:49", Qrt: 1, MinAccountTime: "2019-07-16T11:09:23", MaxAccountTime: "2019-07-16T11:09:23", CashPay: 46.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "001001-8003", OperatorName: "程博平", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T11:55:40", Qrt: 1, MinAccountTime: "2019-07-16T11:55:26", MaxAccountTime: "2019-07-16T11:55:26", CashPay: 45.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "001001-8002", OperatorName: "崔勇", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T11:02:04", Qrt: 1, MinAccountTime: "2019-07-16T10:37:40", MaxAccountTime: "2019-07-16T10:38:26", CashPay: 92.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "001001-8002", OperatorName: "崔勇", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T11:38:26", Qrt: 1, MinAccountTime: "2019-07-16T11:33:49", MaxAccountTime: "2019-07-16T11:33:49", CashPay: 45.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "001001-8001", OperatorName: "徐文龙", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-10T17:17:31", Qrt: 1, MinAccountTime: "2019-07-10T16:49:37", MaxAccountTime: "2019-07-10T17:16:07", CashPay: 95.0 }, { UnitId: "001001", UnitName: "修水县第一人民医院", TeamchkOperatorId: null, TeamchkOperator: null, FdchkOperatorId: null, FdchkOperator: null, TeamchkDt: "0001-01-01T00:00:00", FdchkDt: "0001-01-01T00:00:00", Operator: "001001-8001", OperatorName: "徐文龙", Summary: null, DaylyId: null, Checked: 0, DaylyTime: "2019-07-16T09:28:51", Qrt: 1, MinAccountTime: "2019-07-16T09:25:37", MaxAccountTime: "2019-07-16T09:25:37", CashPay: 9.0 }] var temp = {}; for (var i in this.initagdata) { var key = this.initagdata[i].Operator; if (temp[key]) { temp[key].CashPay += Number(this.initagdata[i].CashPay); temp[key].Operator = this.initagdata[i].Operator; temp[key].UnitId = this.initagdata[i].UnitId; temp[key].UnitName = this.initagdata[i].UnitName; // temp[key].TeamchkOperatorId = this.initagdata[i].TeamchkOperatorId; //班组核销人id // temp[key].TeamchkOperator = this.initagdata[i].TeamchkOperator; //班组核销人 // temp[key].FdchkOperatorId = this.initagdata[i].FdchkOperatorId; //财务核销人id // temp[key].FdchkOperator = this.initagdata[i].FdchkOperator; //财务核销人 // temp[key].TeamchkDt = this.initagdata[i].TeamchkDt; //班组核销时间 // temp[key].FdchkDt = this.initagdata[i].FdchkDt; //财务核销时间 temp[key].OperatorName = this.initagdata[i].OperatorName; //收费员姓名 // temp[key].Summary = this.initagdata[i].Summary; //摘要 // temp[key].DaylyId = this.initagdata[i].DaylyId; //日报号 temp[key].Checked = this.initagdata[i].Checked; //选择 // temp[key].DaylyTime = this.initagdata[i].DaylyTime; //日报时间 temp[key].Qrt += Number(this.initagdata[i].Qrt); //日报笔数 temp[key].MinAccountTime = new Date(temp[key].MinAccountTime).getTime() < new Date(this.initagdata[i].MinAccountTime).getTime() ? temp[key].MinAccountTime : this.initagdata[i].MinAccountTime; //第一笔业务时间 temp[key].MaxAccountTime = new Date(temp[key].MaxAccountTime).getTime() > new Date(this.initagdata[i].MaxAccountTime).getTime() ? temp[key].MaxAccountTime : this.initagdata[i].MaxAccountTime; //最后一笔业务时间 } else { temp[key] = {}; temp[key].CashPay = Number(this.initagdata[i].CashPay); temp[key].Operator = this.initagdata[i].Operator; temp[key].UnitId = this.initagdata[i].UnitId; temp[key].UnitName = this.initagdata[i].UnitName; // temp[key].TeamchkOperatorId = this.initagdata[i].TeamchkOperatorId; // temp[key].TeamchkOperator = this.initagdata[i].TeamchkOperator; // temp[key].FdchkOperatorId = this.initagdata[i].FdchkOperatorId; // temp[key].FdchkOperator = this.initagdata[i].FdchkOperator; // temp[key].TeamchkDt = this.initagdata[i].TeamchkDt; // temp[key].FdchkDt = this.initagdata[i].FdchkDt; temp[key].OperatorName = this.initagdata[i].OperatorName; // temp[key].Summary = this.initagdata[i].Summary; // temp[key].DaylyId = this.initagdata[i].DaylyId; temp[key].Checked = this.initagdata[i].Checked; // temp[key].DaylyTime = this.initagdata[i].DaylyTime; temp[key].Qrt = Number(this.initagdata[i].Qrt); temp[key].MinAccountTime = this.initagdata[i].MinAccountTime; temp[key].MaxAccountTime = this.initagdata[i].MaxAccountTime; } } var newArry = []; for (var k in temp) { newArry.push(temp[k]) } console.log(newArry)