需求: 把红色合为一条数据,绿色合为一条数据
结果:
不多说直接上代码.........................................................
// 先查所有数据
const goods = await service.goods.findAllGoodsWithParams({where: params,offset: ctx.pagination.skip,limit: ctx.pagination.limit,});
// 循环查出数据const map = {};const temp = [];for (let i = 0; i < goods.rows.length; i++) {
// shop_id 是所属店铺字段const good = goods.rows[i];const key = good.shop_id;if (!map[key]) {map[key] = good.shop_id;temp.push(good);}}ctx.status = 200;ctx.body = temp;