作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在和 monk 一起工作,当我使用一个函数在数据库中查找用户时,我希望他们根据是否找到它来返回一个 bool 值。这是代码:
功能:
function userExist() {
users
.find()
.then(result => {
console.log(result)
if(result.length != 0) {
return true;
} else {
return false;
}
})
调用函数(这里是错误):
userExist().then(received => {
console.log(received);
})
最佳答案
您应该在 userExist 函数中返回您的 promise 。否则,您只有一个函数,而不是调用 then() 的 promise 。
function userExist() {
return users
.find()
.then(result => {
console.log(result)
if(result.length != 0) {
return true;
} else {
return false;
}
})
关于javascript - 类型错误 : Cannot read property 'then' of undefined with find() monk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54471144/
我是一名优秀的程序员,十分优秀!