繁体   English   中英

Node.js / Sails.js应用程序中的范围和/或上下文

[英]Scope and/or context in Node.js / Sails.js application

我在Sails.js应用程序上运行此代码,结果是一个空的JSON。 我已经阅读了几个关于范围和背景的页面,并且无法完成我做得不好的事情。

    var evoluciones
    HC.find({ id: req.param('id') }).then(records => {
        evoluciones = records;            
    })
    return res.json(evoluciones)

提前致谢。

@mechuda,你可以试试这个

HC.find({ id: req.param('id') })
  .then(evoluciones=> { 
       // to do something
      return [evoluciones] ; 
    })
  .spread((evoluciones ) => {
          return res.json(evoluciones )
   })
  .fail( error => {
            sails.log.error(error);
            return res.negotiate(error);
   });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM