未定义的错误

时间:2017-02-28 12:58:56

标签: node.js express ejs

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*" } } } } }' 。任何人都可以建议我如何解决它。我错过了什么?

2 个答案:

答案 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});
           }
          });
       });

我认为这就是你想要的。