简体   繁体   English

Loopback自定义远程方法中的数组类型

[英]Array Type in Loopback custom remote methode

I have defined a custom remote method in loopback trying to post some data. 我在回送中定义了一个自定义的远程方法,试图发布一些数据。

Here is the code of the methode definition: 这是方法定义的代码:

  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'},
 });

When posting data with an empty array in exercises everything works fine see: Working without data . 在练习中发布带有空数组的数据时,一切正常,请参见: 无数据工作 But when I insert any information into the array I get an error see: Not Working with data 但是,当我将任何信息插入数组时,我看到一个错误,请参阅: 不使用数据

Hope somebody can help me. 希望有人能帮助我。 Thank you! 谢谢!

You see that error because you send malformed JSON. 您看到该错误是因为发送格式错误的JSON。 You omit quotation marks around id. 您忽略ID周围的引号。 It should look like this: 它看起来应该像这样:

["id": "1"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM