如何在异步咖啡脚本中缩进代码

时间:2016-11-06 14:59:42

标签: node.js sqlite express coffeescript

我的咖啡脚本中有缩进问题!!

我问自己如何将这些代码行放在一起,以便它们顺利运行并且不会跳过任何东西。当我想在我的视图中使用它时,影响是数组 friendsCollection 为空。

我想问题是咖啡脚本(javascript)本身(因为它异步工作)但我不知道如何去做。

现在,这是代码:

app.get '/', (req, res) ->
  brain = req.session
  if brain.userId
    friendsCollection = []
    data.serialize ->
      data.each "select rowid as id, * from friends where userId='#{brain.userId}'", (err, row) ->
        if not err
          if row isnt undefined
            friend =
              name: row.name
              email: row.email
              phone: row.phone
              location: row.location
              relationship: row.relationship
              notes: row.notes
            friendsCollection.push friend
      res.render 'app/index',
        id: brain.userId
        friendsCollection: friendsCollection
  else
    res.render 'notAllowed'

如果有人可以解决这个问题,我会很高兴(一点点)!

0 个答案:

没有答案