我有这个json结构:
{
"sales_rep": {
"1": {
"id": 1,
"name": "Joe",
"email": "joebloggs@email.com",
"customers": [
{
"id": 1,
"address": "1 High Street",
"name": "CUSTOMER1",
"supplierId": 1,
},
{
"id": 2,
"address": "2 High Street",
"name": "CUSTOMER2",
"supplierId": 1,
},
{
"id": 3,
"address": "3 High Street",
"name": "CUSTOMER3",
"supplierId": 1
},
]
}
}
}
是否可以编写一个功能来提供客户数量而不是客户详细信息?我期待最终得到这样的结果:
{
"sales_rep": {
"1": {
"id": 1,
"name": "Joe",
"email": "joebloggs@email.com",
"customers": "3"
}
}
}
我想我需要某种缩减功能,但是我不确定该怎么做。
我遇到的主要问题之一是原始json是使用此Sequelize模型生成的:
let users = db.SalesRep.findAll({
attributes: ['id', 'name', 'email'],
include: [{
model: db.Customers,
as: 'customers',
}],
where: {'id': "1"},
order: orderClause,
offset,
limit,
});
桃花长相依
RISEBY
相关分类