[英]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.