node.js - 函數getByName()中如何使得co執行完才return
给我你的怀抱
给我你的怀抱 2017-05-16 13:43:20
0
2
666

express中判斷使用者登入(使用了sequelize和co)
但是是return res之後才看到console.log中的資訊。如何使得執行完co中的函數才return?

#
给我你的怀抱
给我你的怀抱

全部回覆(2)
Ty80

一般是返回個Promise,使用的地方也要then一下。

UserBLL.GetByName = function(name) {
    return co(function() {
        return yield User.findOne({where: {username: name}})
    })
}

UserBLL.GetByName('xxx').then(function(res) {
    console.log(res)
})
过去多啦不再A梦

雷雷

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!