【发布时间】:2019-04-12 08:30:58
【问题描述】:
我有一个包含以下格式的 json 数据的数组
staff = [
{ "id" : 1,
"name" : "Robert"
},
{ "id" : 2,
"name" : "Peter"
}
]
我正试图获得这些人的指定。有一个接受一组 id 的 API。我正在尝试分批获取 30 个对象的名称。即发送前 30 个对象并获取它们的名称并继续。我尝试保持 for 循环并传递 30 个对象但未成功。
Designation API 提供以下格式的数据。
[
{
"staffId": "26",
"designation": "PRA"
},
{
"staffId": "25",
"designation": "MRA"
}
]
结果 json
员工 = [ {“身份证”:1, “姓名”:“罗伯特”, "staffDesignation": "PRA" }, {“身份证”:2, “名称”:“彼得”, "staffDesignation": "MRA" } ]
因此,对于我获得的每 30 批指定,我需要使用该值更新员工记录。
staff.component.ts
for (让 i = 0; i { //这里传30个对象 //更新指示符逻辑 }, (错误) => {
})
}
staff.service.ts
getStaffDesignator(staff)
{
staff.forEach((staff, index) => {
if (index === 0) {
url = url + `?contactId=${staff.id}`;
}
else {
url = url + `&contactId=${staff.id}`
}
}) //loop through the objects to get the staff id to pass to the APIcall
return this.http.get(url, this.options)
.map((res: Response) => {
return res.json();
}) //API call to get designations for staff
}
【问题讨论】:
-
那么
staff数组中的id是否等于指定数组中的staffId?询问您在 OP 中给出的不同值。该 API 是否会按照对象在staff数组中出现的顺序返回数据? -
@SiddAjmera 是的.. 我们从 API 调用中获取作为 staffId 的密钥.. 这与员工记录中的 id 相同。
-
@indra257 结果 josn 你怎么能在其中管理名字?并且您想根据结果 josn 更新键值。我说的对吗?
-
@SachinShah 是的
-
@indra257 所以基本上你想首先以 30 个批次调用所有 API,然后你想更新键和值。我说的对吗?
标签: angular angular5 angular6 lodash