Loopbackjs 环回添加非静态远程方法错误

Loopbackjs 环回添加非静态远程方法错误,loopbackjs,strongloop,Loopbackjs,Strongloop,我正在尝试将非静态远程方法添加到模型中。沿着这条路走。不幸的是,我收到了一些错误消息 下面是我的代码 User.prototype.lastOrder = function(callback){ console.log('print this instance object: ', this); callback(null) }; User.remoteMethod('__get__lastOrder', { isStatic: false, accepts: [], de

我正在尝试将非静态远程方法添加到模型中。沿着这条路走。不幸的是,我收到了一些错误消息

下面是我的代码

User.prototype.lastOrder = function(callback){
  console.log('print this instance object: ', this);
  callback(null)
};

User.remoteMethod('__get__lastOrder', {
  isStatic: false,
  accepts: [],
  description: 'Get the latest order of the user',
  http: {
    path: '/lastOrder',
    verb: 'get'
}
当我调用
http://localhost:3000/v1/users/1/lastOrder
。它给了我以下错误:


remoteMethod的第一个参数是函数名。您定义的内容无效。您需要定义一个名为lastOrder的函数,然后修改代码,如下所示:

User.prototype.lastOrder = function() {

}

User.remoteMethod('lastOrder', {
  isStatic:false,
  //more stuff here
}

您好,我已经用这种方式尝试过了,仍然是相同的错误。请参阅下面我的评论。你发布了一个新的答案。这对你有用吗?@RaymondCamden。对它是一个静态方法,因此应该是
User.prototype.lastOrder
。我以为你打错了,所以我贴出了完全正确的答案,只是为了避免误导他人。无论如何,我会接受你的答案,但我会更正你的答案。谢谢你的澄清。我可以发誓,文档中说的所有情况下都使用Model.NAME,即使是非静态的,但这是有道理的,因为它将在prototype下。@RaymondCamden,你能不能仔细查看我对你答案的编辑。在定义上加上“原型”。早上我会再次检查你是否正确。我就是不相信。无意冒犯-我仍在学习自己,我需要看到这一点,相信它你好,@RaymondCamden,然后转到
选项
部分。它在
isStatic
关键字中提到<代码>布尔值。方法是否是静态的(例如MyModel.myMethod)。使用false定义原型上的方法(例如,MyModel.prototype.myMethod)。默认值为true。
  User.prototype.lastOrder = function(callback){
    console.log('print this instance object: ', this);
    callback(null, "this is a test");
  };

  User.remoteMethod('lastOrder', {  // should be lastOrder not __get__lastOrder
    isStatic: false,
    accepts: [],
    description: 'Get the latest order of the user',
    http: {
      path: '/lastOrder',
      verb: 'get',
      status: 200
    },
    returns: {root: true, type: 'order'}
  });