1 回答
TA贡献1946条经验 获得超3个赞
试试下面的代码片段,它应该可以解决问题。
fetch('/api/v1/organizationrelationship/organizationprograms', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
})
.then(res => res.json())
.then(res => {
if(res) {
// gets all the ids from the response and make them a set to remove duplicate
let ids = new Set(res.proprams.map( (program, index) => return program.programId));
// convert the set into and array and the use the toString function to make them comma seperated
let params = Array.from(ids).toString()
fetch(`/api/v1/program/programlist/${params}`, { // this is passing all 4 programId individually
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
})
.then(res => res.json())
.then(res => {
if(res) {
//here you can now save the response to state
console.log("res: ", res)
}
})
}
})
添加回答
举报