0
該函數將返回一個包含商店細節和圖像的數組。在nodejs中合併兩個數組
function listshops(callback)
{
var array=[3,4];
async.each(array,function(dat,callback){
async.parallel([
function(callback){
c function listshops(callback)
{
var array=[3,4];/*shopId*/
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);
});
});
}
對於上述代碼的輸出是:: http://i.stack.imgur.com/laxf8.png
我需要包含店鋪信息和圖像轉換成單個array.That陣列合併與相應的圖像店鋪信息。
[
{ shopId: 3, shopName: '1', address: 'abc', contactNumber: 1234 },
{ imageId: 1, shopId: 3, imageUrl: 'aaa' },
{ imageId: 2, shopId: 3, imageUrl: 'bbb' }
]
你寫的代碼完美無缺。但這裏的問題是:{{shopId:3,shopName:'1',地址:'abc',contactNumber:1234}, {imageId:1,shopId:3,imageUrl:'aaa'}, {imageId: 2,shopId:3,imageUrl:'bbb'}] {{shopId:4,shopName:'2',地址:'bbb',contactNumber:1234}, {imageId:3,shopId:4,imageUrl:' ccc'}, {imageId:4,shopId:4,imageUrl:'ddd'}]從這個數組中如何檢查shopId = 3的數據。 –
當我給結果[0]它提取了兩個商店的細節。當我給結果[1]它獲取圖像id(1,3)。 –
http://stackoverflow.com/questions/37695717/json-array-is-not-getting-in-expected-format:請檢查這個問題。 –