我在远程方法的查找中使用简单的排序过滤器很难:
/**
* This remote method exposes the meals history from the current logged in user
*/
Meal.listMeals = function(req, res, cb) {
Meal.find({
where: {patientId: req.accessToken.userId},
order: {mealDate: 'DESC'}
}, cb);
};
Meal.remoteMethod('listMeals', {
returns: {arg: 'meals', type: 'array'},
http: {path:'/list-meals', verb: 'get'},
accepts: [
{arg: 'req', type: 'object', http: {source: 'req'}},
{arg: 'res', type: 'object', http: {source: 'res'}}
]
});
上面你看到我的远程/查找实现,它没有订单过滤器正常工作..一旦我添加oder {mealDate:'DESC'}我收到错误:
订单{“mealDate”:“DESC”}无效
mealDate是我模型上的日期类型。
"properties": {
"mealDate": {
"type": "date",
"required": true,
"default": "Date.now"
},
任何想法可能是什么问题?我已经坚持了一段时间,我想解决方案很简单..
P.S - 我知道我可以在数组中使用sort direct来执行此操作,但在这种情况下我尝试使用环回过滤器。
答案 0 :(得分:5)
基于doc,我认为它应该是这样的:
Meal.find({
where: {patientId: req.accessToken.userId},
order: 'mealDate DESC'
}, cb);
答案 1 :(得分:0)
环回4:
Meal.find({
where: {patientId: req.accessToken.userId},
order: ['mealDate DESC'],
});