for my Bachelor thesis I am required to build a Web frontend/ visualisation for a business process, using javascript. This process is stored inside a neo4j database (version 2.1.7) and I am using meteor together with the driver, which is recommended on neo4j's website (version 2.10).
Since I am fairly new to Web development in general and especialy to javascript, I am not sure if my problem is of a technical or knowledge (aka me being a beginner) nature.
At the moment I am working on a function, which should give me back a node from the database (currently "a node" equals a node's id, since the final representation of a node on the webpage is not yet decided).
getNodeById = function getNodeById(id){
console.log("The given id is " + id);
var result = undefined;
N4JDB.getNodeById(id, function getNode(node) {
console.log ("The node's id is " + node.id);
console.log("Result before " + result );
result = node.id;
console.log("Result after " +result);
});
return result;
}
Calling getNodeById(4) gives me the following output on meteor's console:
I20150309-16:03:32.200(1)? The given id is 4 I20150309-16:03:32.272(1)? The node's id is undefined I20150309-16:03:32.272(1)? Result before undefined I20150309-16:03:32.272(1)? Result after undefined
The problem right now is, that I am not sure how to write a callback function, which fits for the drivers getNodeById function.
Link to the driver's documentation: https://atmospherejs.com/ostrio/neo4jdriver
Edit:Further debugging has lead me to believe, that I make a mistake somewhere/how when invoking N4JDB.getNodeById since it always returns null
New function (require statement on top of the file, since there will be many functions similar to this one)looks like this
getNodeById = function getNodeById(id){
var myFuture = new Future ();
var result = undefined;
N4JDB.getNodeById(id, function getNode(node){
console.log(node);
result = node.id;
myFuture.return(result);
});
return myFuture.wait();
}
Final edit: It worked with
getNodeById = function getNodeById(id){
var myFuture = new Future ();
var result = undefined;
N4JDB.getNodeById(id, function getNode(err,node){
//console.log(node);
result = node.id;
myFuture.return(result);
});
return myFuture.wait();
}