2

私は配列を持っています。いくつかの編集を使用して再コンパイルする必要があります。の助けを借りてそれを行いますがasync.concat()、何かが機能していません。教えて、どこが間違っているの?

async.concat(dialogs, function(dialog, callback) {
    if (dialog['viewer']['user_profile_image'] != null) {
        fs.exists(IM.pathToUserImage + dialog['viewer']['user_profile_image'].replace('%s', ''), function(exits) {
            if (exits) {
                dialog['viewer']['user_profile_image'] = dialog['viewer']['user_profile_image'].replace('%s', '');
            }
            callback(dialog);
        });
    }
}, function() {
    console.log(arguments);
});

私の意見では、すべてが論理的です。コールバックは、最初の反復の直後に呼び出されます。しかし、配列全体の処理が完了した後、どうすればデータを送信できますか?

ありがとうございました!

4

3 に答える 3

2

問題を解いたのですが、意味がわかりませんでした。問題は、処理された値ではなく null の要素が原因でした。この時点でプログラムは中断しましたが、エラーや警告を破棄しないでください。

async.map(dialogs, function(dialog, callback) {
    if (dialog['viewer']['user_profile_image'] == null) {
        dialog['viewer']['user_profile_image'] = IM.pathToUserImage;
    }
    fs.exists(IM.pathToUserImage + dialog['viewer']['user_profile_image'].replace('%s', ''), function(exits) {
        if (exits) {
            dialog['viewer']['user_profile_image'] = dialog['viewer']['user_profile_image'].replace('%s', '');
        }
        callback(null, dialog);
    });
}, function(err, rows) {
    if (err) throw err;
    console.log(rows);
});
于 2013-07-17T15:17:59.843 に答える