有这样的要求:
public GetJobsListExcel(jobs: JobViewModel[] ): Promise<string> {
let JobIds: number[] = [];
jobs.forEach(x => JobIds.push(x.JobId));
let url = `/api/job/jobs-list-excel?jobIds=${JobIds}`;
return this.http.get(url)
.toPromise()
.then(response =>
response.text() as string
);
}
它会生成如下参考:/ api / job / jobs-list-excel? JobIds = $ 1,2,3 e.t.c 你需要的是这样的:/ api / job / jobs-list-excel? JobIds = 1美元? JobIds = 2美元? JobIds = $ 3
我试过大家,不出门,朝什么方向挖?谢谢。
答案 0 :(得分:0)
我建议您将JobIds
传递给API ,
分隔的number
列表作为字符串
let url = `/api/job/jobs-list-excel?jobIds=${JobIds.join(',')}`
服务器端split
JobIds字符串,
(逗号)
答案 1 :(得分:0)
如果您需要在问题中提出多个JobIds
查询字符串
let url = `/api/job/jobs-list-excel?JobIds=${JobIds.join('&JobIds=')}`
// => "/api/job/jobs-list-excel?JobIds=1&JobIds=2&JobIds=3&JobIds=4"