route.js
router.get('/restful', function(req, res){
console.log("before");
User.show_deatils(req, res, function(err, resultArray){
if(!err) {
req.session.resultArray=resultArray;
}
});
console.log(req.session.resultArray);
res.render('restful',{resultArray:req.session.resultArray});
});
我不知道为什么当我在上面的位置undefined
进行console.log()
时我得到console.log()
。如果我在req.session.resultArray=resultArray
之后resultArray
那么我们得到结果数组。
我想在view.ejs
中显示此curl -s -XGET 'localhost:9200/index_name/type/_search?pretty=true&size=10' -d '{
"query": {
"bool": {
"must": {
"match": {
"logtype": "error"
}
},
"must_not": {
"match": {
"logMessage": "*error occured*"
}
}
}
}
}'
。任何人都可以建议我如何解决它。我错过了什么?
答案 0 :(得分:0)
在异步函数实际从数据库中获取详细信息之前,console.log运行。所以你得到了不确定。 在回调中进行渲染。即,在将结果数组分配给会话之后。
Error in MulticastDelegate PlayerConnected: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.OverflowException: Value is too large
at System.Int16.Parse (System.String s) [0x00000] in <filename unknown>:0
at SQLPlayer.SQLPlayer.Events_OnPlayerConnected (Rocket.Unturned.Player.UnturnedPlayer player) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0
at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0
at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0
at Rocket.Core.Extensions.MulticastDelegateExtension.TryInvoke (System.MulticastDelegate theDelegate, System.Object[] args) [0x00000] in <filename unknown>:0
答案 1 :(得分:0)
就这样做
router.get('/restful', function(req, res){
console.log("before");
User.show_deatils(req, res, function(err, resultArray){
if(!err) {
res.render('restful',{resultArray:resultArray});
}
});
});
我认为这就是你想要的。