SailsJS | TypeError: Cannot read property 'then' of undefined
SailsJS | TypeError: Cannot read property 'then' of undefined
我在 'GET' 这个控制器操作时得到这个错误:
TypeError: Cannot read property 'then' of undefined
代码:
allUsers: function (req, res) {
Admin.find({ id: req.adminId }, function (err, admin) {
console.log(admin);
})
.then(function onSuccess(admin) {
return User.find(function (err, users) {
res.json(users);
});
})
.catch(function onError(res) {
return res.status(401).send();
});
}
有什么想法吗?
您似乎在尝试混合回调和承诺风格。
如果删除部分会发生什么:
, function (err, admin) {
console.log(admin);
}
根据 Sails.js ORM documentation,承诺样式 find
是这样设计的:
Zookeeper.find()
.then(function (zookeepers) {...})
.catch(function (err) {...});
我在 'GET' 这个控制器操作时得到这个错误:
TypeError: Cannot read property 'then' of undefined
代码:
allUsers: function (req, res) {
Admin.find({ id: req.adminId }, function (err, admin) {
console.log(admin);
})
.then(function onSuccess(admin) {
return User.find(function (err, users) {
res.json(users);
});
})
.catch(function onError(res) {
return res.status(401).send();
});
}
有什么想法吗?
您似乎在尝试混合回调和承诺风格。 如果删除部分会发生什么:
, function (err, admin) {
console.log(admin);
}
根据 Sails.js ORM documentation,承诺样式 find
是这样设计的:
Zookeeper.find()
.then(function (zookeepers) {...})
.catch(function (err) {...});