V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
erichuang1994
V2EX  ›  问与答

node.js 回调函数的问题

  •  
  •   erichuang1994 · 2015-05-10 01:04:55 +08:00 · 1450 次点击
    这是一个创建于 3291 天前的主题,其中的信息可能已经有所发展或是发生改变。
    passport.use('local', new LocalStrategy(
            function (username, password, done) {
        //        var get_result = function(username,callback) {
        //              var user=dbms.find(username);        
        //        }
        //        get_result(function(data){
        //            console.log(data)
        //        })
                console.log('get password:',password);
                var user=dbms.find(username)
                console.log('user:',user);
                if (username !== user.username) {
                    return done(null, false, { message: 'Incorrect username.' });
                }
                if (password !== user.password) {
                    return done(null, false, { message: 'Incorrect password.' });
                }
                return done(null, user);
            }
        ));
    

    小白求教一下,上面的代码里面dbms.find(username)是一个回调函数,可是我希望等到数据库查询结果赋给user后在执行下面的判断,应该怎么改?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   6197 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 01:45 · PVG 09:45 · LAX 18:45 · JFK 21:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.