我在回送中定义了一个自定义的远程方法,试图发布一些数据。
这是方法定义的代码:
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'},
});
在练习中发布带有空数组的数据时,一切正常,请参见:Working without data。但是,当我将任何信息插入数组时,我会看到错误:Not Working with data
希望有人可以帮助我。谢谢!
答案 0 :(得分:0)
您看到该错误,因为您发送格式错误的JSON。您忽略ID周围的引号。它应该看起来像这样:
["id": "1"]