0
当我在运行“node jkl.js”的同时在我的“exports.findOneProblem”中使用console.log(result)时,它目前工作正常。我能看到结果。但是,当我使用return而不是console.log()时,我得到的只是控制台中的Promise {pending}。请填写空白....学习如何与承诺一起工作,谢谢。异步问题,JS Promise无法返回结果,但与console.log一起工作
//asd.js
exports.findOneProblem = function(problemId) {
return RClient.authenticate(options).then(function (client) {
const Problem = client.Problem;
return Problem.findOne(problemId)
}).then(function(result){
return result
});
};
第二个文件:jkl.js
var okay = require('./asd');
var moneymoney = okay.findOneProblem(263)
console.log(moneymoney)
var honeyhoney = moneymoney.then(function(result){
return result
})
console.log(honeyhoney)
哦,我的!谢谢。 –