最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何执行发送 id 数组的异步 get() 请求,但不想遍历整个异步获取数组请求

网站源码admin35浏览0评论

如何执行发送 id 数组的异步 get() 请求,但不想遍历整个异步获取数组请求

如何执行发送 id 数组的异步 get() 请求,但不想遍历整个异步获取数组请求

      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();
    }

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

这是这个获取请求的API:

// get template_rowID
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));
 });


});
回答如下:
发布评论

评论列表(0)

  1. 暂无评论