簡體   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