gpt4 book ai didi

node.js - async.parallel 用于多个数据

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:21 26 4
gpt4 key购买 nike

这是一个async.parallel方法,用于显示商店信息及其对应的图像:

 function listshops(callback)
{
async.parallel([
myFirstFunction,
mySecondFunction,
], function (err,results) {

console.log(results);
});


function myFirstFunction(callback) {

client.connection.query('select * from shop',function(err,data1){
callback(null,data1);
});
}


function mySecondFunction(callback) {
client.connection.query('select * from image',function(err,data2){
callback(null,data2);

});
}

1)我的 table =>商店和图片:/image/F20MU.png

2)我的代码得到输出。但这不是我期望的输出: /image/ltJpf.png

3)预期输出:/image/xAmvu.png

最佳答案

function listshops(callback)
{
var array=[3,4];
async.each(array,function(dat,callback){

async.parallel([

function(callback){
client.connection.query('select * from shop where shopId=?',dat,function(err,data1){
callback(null,data1);

});
},

function (callback) {
client.connection.query('select * from image where shopId=?',dat,function(err,data2){
callback(null,data2);

});
}
],
function(err,data)
{
console.log(data);

});
});

}

关于node.js - async.parallel 用于多个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37673507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com