node.js - Pass a block variable to a callback function that has already arguments -
this callback:
function evaluateserviceresponse(err, response){ db.answercollection.insert({id: response["serviceanswer"]["id"]}); //problem line } this callback-user:
mysoapclient.invokeservicemethod(jsonrecords,this.evaluateserviceresponse); here whole code. inside process create block reference database:
process(function(){ ... let db=null; db = mongoclient.connect(connectionurl); //do whatever create jsonrecords mysoapclient.invokeservicemethod(jsonrecords,this.evaluateserviceresponse); ... }); the invokeservicemethod talks service calls callback passing service response.
how db reference callback evaluateserviceresponse?
thanks.
use closure :
function evaluateserviceresponse(db){ return function(err, response){ db.answercollection.insert({id: response["serviceanswer"]["id"]}); //problem line } } and use like:
mysoapclient.invokeservicemethod(jsonrecords,this.evaluateserviceresponse(db));
Comments
Post a Comment