0
我是新来的回环,我试图在使用findyById方法的回环中创建一个简单的远程方法。花了几个小时在这个上,仍然无法让它工作。这里是我的代码:loopbackjs - findById需要ID参数
customer.js:
Customer.list = function(customerId, cb){
app.models.Customer.findById(customerId, function (err, instance) {
cb(null, err || 'success');
if(err){
console.log(err);
}else if(instance){
console.log(instance);
}
});
}
// expose the above method through the REST
Customer.remoteMethod('list', {
returns: {
arg: 'list',
type: 'string'
},
accepts: {arg: 'id', type: 'number', http: { source: 'query' } },
http: {
path: '/list',
verb: 'get'
}
});
customer.controller.js:
Customer.list(1)
.$promise
.then(function(response){
console.log(response);
})
.catch(function(err){
console.log(err);
});
我的客户排在MySQL:
ID:1号:10
我收到此错误:
Error: Model::findById requires the id argument
at Desktop\SampleProject\node_modules\loopback-datasource-juggler\lib\dao.js:1287:10
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
能否告诉我可能的原因/为什么我得到这个错误? 请帮帮我。谢谢