简体   繁体   English

如何在函数JS + Cypher中访问值

[英]How can I access to value inside a function JS + Cypher

This is a query with de Neo4j js driver. 这是使用de Neo4j js驱动程序的查询。 The query works fine, and I can get the value in the var x . 查询工作正常,我可以在var x获取值。 But the value only can be access inside the function g. 但是该值只能在函数g中访问。 If I try to call the function I have a message that said that g is no defined. 如果我尝试调用该函数,则会收到一条消息,指出未定义g。 (thank you for your help) (谢谢您的帮助)

session
    .run( "MATCH (a:Autor) RETURN a.nombre AS name") 
    .then( 
        function g( result ) { 
            var x=result.records[0].get("name");//ok, x take the value
            console.log('es '+x); //ok, print the first value of the db
            session.close();
            return x;
        });
var r=g(); //error Uncaught ReferenceError: g is not defined
console.log('es '+r); //do not execute this part

try this : 尝试这个 :

var result = session
.run( "MATCH (a:Autor) RETURN a.nombre AS name") 
.then( 
    function g( result ) { 
        var x=result.records[0].get("name");//ok, x take the value
        console.log('es '+x); //ok, print the first value of the db
        session.close();
        return x;
    });

Now to get the result anywhere, simply do this : 现在要在任何地方获得结果,只需执行以下操作:

result.then( function (data) { console.log('es' + data) });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何访问映射函数中的变量值? - How can I access a value of a variable inside a map function? 如何更新 function 内部的全局 object 的值,然后在 JS 中使用另一个 function 访问其值? - How can I update the values of a global object inside of a function and then access its values with another function in JS? JS:如何访问另一个函数内部的函数中的变量值,并且两个函数都属于同一对象? - JS: How may I access a variable value inside a function that's inside another function, and that both functions belong to the same object? 如何访问在另一个函数 JS 中定义的变量值 - How to access a variable value that is defined inside another function JS 如何在JQUERY中访问不同js文件中的函数? - How can I access the function which inside different js file in JQUERY? 如何在函数内部更改值? - How can I change a value inside of a function? 如何访问react Context.Provider值内的另一个函数? - How can I access another function inside the react Context.Provider value? 如何在通常的JS函数中访问JQuery属性 - How do I access JQuery property inside a usual JS function 如何在循环内运行异步 function 并获取返回值(Node.js/Javascript) - How can I run an asynchronous function inside a loop and get a return value (Node.js/Javascript) 如何更改 node.js 中 function 中的变量值? - How can i change the value of a variable inside a function in node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM