Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
node.js-传递到回调时字典会更改_Node.js_Neo4j - Fatal编程技术网

node.js-传递到回调时字典会更改

node.js-传递到回调时字典会更改,node.js,neo4j,Node.js,Neo4j,我使用async.map函数在“arrayOne”的每个元素上调用neo4j数据库 第一个console.log显示我想要的内容: [{世界其他地区:['DIE ZAUBERFLOETE-2013',1355]}] 但最终函数中的第二个console.log不显示相同的结果: [{行:[对象]}] 它来自哪里?我希望在第二个console.log中得到相同的结果 注意:getClientsNb函数如下所示: function getClientsNb(param, callback) {

我使用async.map函数在“arrayOne”的每个元素上调用neo4j数据库

第一个console.log显示我想要的内容:

[{世界其他地区:['DIE ZAUBERFLOETE-2013',1355]}]

但最终函数中的第二个console.log不显示相同的结果:

[{行:[对象]}]

它来自哪里?我希望在第二个console.log中得到相同的结果

注意:getClientsNb函数如下所示:

function getClientsNb(param, callback) {
    request.post({
        uri: httpUrlForTransaction,
        json: {statements: [{
            statement: 'MATCH (n:Show {id:{id}})<-[:BUYS]-(m) RETURN n.name, count(distinct m)', 
            parameters: param}]}
        },
    function (err, res, body) {
        if (err) {
            console.log(err);
            return callback(err)
        } else {
            return callback(null,body)
        }
    }).auth('neo4j', password, true);
}
函数getClientsNb(参数,回调){ 请寄({ uri:httpUrlForTransaction, json:{语句:[{ 语句:“MATCH(n:Show{id:{id}})[已编辑]

通过更改第二个console.log()调用以JSON形式输出数据,可以显示有关实际返回内容的更多详细信息:
console.log(“%j”,res);
。结果可能是
对象中的

附加问题 这可能解决不了您所询问的问题,但在错误处理方面确实存在逻辑错误

async.map()
要求对数组中的每个项调用它的
回调
。但是在您的代码中,如果传递给
getClientsNb()
的匿名回调被传递了
err
值,它将返回而不调用
回调

此代码修复了上述问题:

async.map(
    arrayOne,
    function(item, callback){
        getClientsNb({id:item}, function (err, res) {
            if (err) { console.log(err); return callback(err); }
            console.log(res.results[0].data); //1
            callback(null,res.results[0].data);
        });
    }, 
    function(err,res) {
        if (err) return console.log(err);
        console.log(res); //2
    }
)

我已经编辑了我的帖子,感谢您的帮助。但是这并不能解决我的问题。请更改第二个console.log()调用,将数据输出为JSON,以显示有关实际返回内容的更多详细信息:
console.log(“%j”,res)
。谢谢,我这样做了,我发现我的结果实际上被传递到了最后一个函数,我只需要访问它。
async.map(
    arrayOne,
    function(item, callback){
        getClientsNb({id:item}, function (err, res) {
            if (err) { console.log(err); return callback(err); }
            console.log(res.results[0].data); //1
            callback(null,res.results[0].data);
        });
    }, 
    function(err,res) {
        if (err) return console.log(err);
        console.log(res); //2
    }
)