1 回答

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
試試下面的代碼片段,它應(yīng)該可以解決問題。
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)
}
})
}
})
添加回答
舉報(bào)