从每一行都是自定义类型的数组发送一个 Id,但是发送每个数组而不在 javascript 中循环

问题描述 投票:0回答:0

我有一个变量:

worksheetmatrixRows: Array < templateWMS > = [];

 for (let i = 0; i < this.selectedworksheets.length; i++) {
  specific_templateRowId = await this.httpClient.get < Array<number>> (`${GLOBAL.BASE_URL}/templaterow/${this.worksheetmatrixRows[i].Id}`).toPromise();
}

templateWMS 看起来像:

  export interface templateWMS {
    Id: number;
    Name: string;
    TemplateCreated: string;
    No: string;
    VersionNo: string;
    StatusId: number;
    ValidFor: string;
    CanBeChanged: number;
    IsMainSheet: number;
    IsActive: number;
    AuthorId: number;
    CategoryId: number;
    ApprovalId: number;
    ApprovalDate: string;
    ReviewId: number;
    ReviewDate:string;
  }

我想在不循环的情况下发送所有数组元素,因为通过循环多次调用 get 请求。来自后端的响应是一个数组,我希望将响应保存为一个数组,但由于有多个 get 请求,该数组不会保存所有响应,而只保存它们自己的 get 请求的响应。

这是这个获取请求的API:

app.get('/templaterow/:ID', function (req, res) {
logging('[GET] /templaterow');

console.dir(req.params.ID);
fetched_templatewrowIDs =[];
templateID = req.params.ID

async.eachSeries(templateID, function(elem, callback) {
// Get this Vehicle from DB
let sql = `SELECT Id FROM template_row WHERE TemplateId = ${req.params.ID} AND RowNo= 1`;
 console.dir(sql);
wmsconn
    .query(sql, function (err, rows, fields) {
        if (err)            
            throw err;

     
        
        fetched_templatewrowIDs.push(JSON.stringify(rows[0].Id));
        console.log('The solution is: ', fetched_templatewrowIDs);
       
       callback();
    });

}, function(err, arrayOfTests) {
    // All SQL statements are finished
    console.log("ASYNC SERIES finished. Returning these 'newTemplaterowids' :");
    console.log("After the  callback WMS ID array ", fetched_templatewrowIDs);
    res.send(JSON.stringify(fetched_templatewrowIDs));
 });


});
arrays json angular get
© www.soinside.com 2019 - 2024. All rights reserved.