我有下面的JSON响应,它是作为远程对象下的ID组返回的。
然而,要在UI上显示,我需要根据名称分组后显示数据。有人可以建议我如何根据已经由后端API分组的数据的名称对数据进行分组吗?
有人能帮忙吗。
电流响应:
{
"remote": {
"12345": [
{
"id": "642232324873ab98",
"name": "Akon",
"account_id": "12345",
"account_name": "director"
}
],
"56780": [
{
"id": "6434343a1873ab98",
"name": "Jim",
"account_id": "56780",
"account_name": "director"
}
],
"others": [
{
"id": "6421ca1873ab980001bd465a",
"account_id": null
"account_name": "others"
}
]
}
远程对象的预期输出:
"remote": {
"director": [
{
"id": "6420691873ab98",
"name": "Akon",
"account_id": "12345",
"account_name": "director"
},
{
"id": "622121873ab98",
"name": "Jim",
"account_id": "56780",
"account_name": "director"
}
],
"others": [
{
"id": "6421ca1873ab980001bd465a",
"account_id": null,
"account_name": "others"
}
]
}
```
1条答案
按热度按时间dwbf0jvd1#
这是一个非常简单的聚合,代码希望是相当自我解释的。它获取
remote
下的所有条目,并尝试将它们聚合到一个新数组中,该数组由account_name
或字符串“other”(如果不存在)分组。