Loopback 自定义远程方法中的数组类型
Array Type in Loopback custom remote methode
我在环回中定义了一个自定义远程方法,试图 post 一些数据。
这里是方法定义的代码:
Workout.prototype.greet = function(userId, exercises, cb) {
cb(null, userId + ' ' + this.id);
}
Workout.remoteMethod('prototype.greet', {
accepts: [{arg: 'userId', type: 'string', required: true, description:"MyUserId for who created the challenge", http: { source: 'query' }},
{arg: 'exercises', type: 'array', required: true, description:"Array of exercises which should be added", http: { source: 'body' }}],
returns: {arg: 'greeting', type: 'object'},
});
当 post 在练习中使用空数组处理数据时,一切正常,请参阅:Working without data. But when I insert any information into the array I get an error see: Not Working with data
希望有人能帮助我。谢谢!
您看到该错误是因为您发送格式错误 JSON。您省略了 id 两边的引号。它应该是这样的:
["id": "1"]
我在环回中定义了一个自定义远程方法,试图 post 一些数据。
这里是方法定义的代码:
Workout.prototype.greet = function(userId, exercises, cb) {
cb(null, userId + ' ' + this.id);
}
Workout.remoteMethod('prototype.greet', {
accepts: [{arg: 'userId', type: 'string', required: true, description:"MyUserId for who created the challenge", http: { source: 'query' }},
{arg: 'exercises', type: 'array', required: true, description:"Array of exercises which should be added", http: { source: 'body' }}],
returns: {arg: 'greeting', type: 'object'},
});
当 post 在练习中使用空数组处理数据时,一切正常,请参阅:Working without data. But when I insert any information into the array I get an error see: Not Working with data
希望有人能帮助我。谢谢!
您看到该错误是因为您发送格式错误 JSON。您省略了 id 两边的引号。它应该是这样的:
["id": "1"]