I am trying to add a non-static remote method to a model. Just follow the code here. Unfortunately, I got some error message.
我正在尝试向模型添加非静态远程方法。只需按照此处的代码。不幸的是,我收到了一些错误消息。
The following is my code
以下是我的代码
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'
}
And when I invoke http://localhost:3000/v1/users/1/lastOrder
. it gives me the following error:
当我调用http:// localhost:3000 / v1 / users / 1 / lastOrder时。它给了我以下错误:
2 个解决方案
#1
2
The first argument to remoteMethod is the function name. What you have defined isn't valid. You need to define a function called, well, let's say lastOrder, and then modify your code like so:
remoteMethod的第一个参数是函数名。您定义的内容无效。你需要定义一个名为的函数,好吧,让我们说lastOrder,然后像这样修改你的代码:
User.prototype.lastOrder = function() {
}
User.remoteMethod('lastOrder', {
isStatic:false,
//more stuff here
}
#2
2
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'}
});
#1
2
The first argument to remoteMethod is the function name. What you have defined isn't valid. You need to define a function called, well, let's say lastOrder, and then modify your code like so:
remoteMethod的第一个参数是函数名。您定义的内容无效。你需要定义一个名为的函数,好吧,让我们说lastOrder,然后像这样修改你的代码:
User.prototype.lastOrder = function() {
}
User.remoteMethod('lastOrder', {
isStatic:false,
//more stuff here
}
#2
2
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'}
});