我正在使用环回为我的应用程序提供 API,并且我尝试更改某些数据的 GET 请求。
截至目前,查询获取特定 API 的所有结果:
People.find({
where: {
'town': 'name of a town'
}
}).$promise
// Promise is fulfilled and people returned
.then(function(results) {
$scope.people = results;
})
// Promise is rejected and error catched
.catch(function(err) {
$scope.errors.PeopleFind = JSON.stringify(err.data.error.message ?
err.data.error.message :
err.data.error.errmsg
);
});
我已经尝试在 where 子句中添加单引号或执行类似 .find({ where : { town : 'name of a town' }}
的操作。
无论我把引号放在哪里,结果总是完整的。我如何查询我感兴趣的结果?
提前致谢
最佳答案
感谢同事找到答案,我把答案写在这里
People .find({ filter: { where: {Town : currentUserTown} } })
loopback 框架的文档没有说明您需要应用过滤器对象来实际过滤结果,事实上您可以通过他们写的这个示例查看文档:
Cars.find({where: {carClass:'fullsize'}});
在 where 子句对象之前,您需要编写包含该子句的过滤器对象,这应该可以解决查询问题。
关于javascript - loopback Find() "where"子句未返回预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42689296/