Loopback - 创建带有字段的获取请求
Loopback - Creating a get request with fields
您好,感谢您花时间帮助我,
所以我是环回的新手,我想创建一个从数据源检索所有数据但仅检索特定字段的请求。
loopback guide的教程我都看完了,但是还是不懂怎么继续。
基本上我所拥有的是:
XXXX.getUserWithXXXX = function(cb) {
cb(null, 'Greetings... ');
}
XXXX.remoteMethod('getUserWithXXXX', {
description: "Get all users who own a XXXX",
returns: {arg: 'greeting', type: 'string'},
fields: {id: true, email: true},
http: {path: '/getUserWithXXXX', verb: 'get'}
});
首先,我想创建一个请求,从我的模型中检索所有数据,这样我就可以过滤它
然后不知道怎么在代码里过滤
如果有人有任何提示,我很乐意采纳。
将 GET 过滤器放在 "accept" 属性中,并对文档的 return 特定字段使用 "fields" 过滤器。
XXXX.getUserWithXXXX = function(id, email, cb) {
app.models.XXXX.find({where:{id:"id", email:"email"}, fields:{specific_field1:1, specific_field2:1}}, function(err, returnedUsers){
cb(err, returnedUsers)
})
}
XXXX.remoteMethod('getUserWithXXXX', {
description: "Get all users who own a XXXX",
returns: {arg: 'greeting', type: 'string'},
accepts: [{arg: "id",type:"string"}, {arg: "email", type:"string"}],
http: {path: '/getUserWithXXXX', verb: 'get'}
});
您好,感谢您花时间帮助我,
所以我是环回的新手,我想创建一个从数据源检索所有数据但仅检索特定字段的请求。 loopback guide的教程我都看完了,但是还是不懂怎么继续。
基本上我所拥有的是:
XXXX.getUserWithXXXX = function(cb) {
cb(null, 'Greetings... ');
}
XXXX.remoteMethod('getUserWithXXXX', {
description: "Get all users who own a XXXX",
returns: {arg: 'greeting', type: 'string'},
fields: {id: true, email: true},
http: {path: '/getUserWithXXXX', verb: 'get'}
});
首先,我想创建一个请求,从我的模型中检索所有数据,这样我就可以过滤它 然后不知道怎么在代码里过滤
如果有人有任何提示,我很乐意采纳。
将 GET 过滤器放在 "accept" 属性中,并对文档的 return 特定字段使用 "fields" 过滤器。
XXXX.getUserWithXXXX = function(id, email, cb) {
app.models.XXXX.find({where:{id:"id", email:"email"}, fields:{specific_field1:1, specific_field2:1}}, function(err, returnedUsers){
cb(err, returnedUsers)
})
}
XXXX.remoteMethod('getUserWithXXXX', {
description: "Get all users who own a XXXX",
returns: {arg: 'greeting', type: 'string'},
accepts: [{arg: "id",type:"string"}, {arg: "email", type:"string"}],
http: {path: '/getUserWithXXXX', verb: 'get'}
});