I try override find api of strongloop rest endpoint. I want to return an array of objects. But how do I specify the schema for the object? As you can see from the picture above, the model schema is empty.
我尝试覆盖strongloop rest endpoint的find api。我想返回一个对象数组。但是如何指定对象的架构?从上图中可以看出,模型架构为空。
Below is the code of my company model remoteMethod:
以下是我公司型号remoteMethod的代码:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: 'array', root: true},
http: {path: '/', verb:'get'}
}
)
1 个解决方案
#1
3
If I understand you right, your'e trying to show at this section the returned model as follows:
如果我理解你的话,你试图在这一部分显示返回的模型如下:
[
{
"companyProperty1": "companyProperty1Type",
"companyProperty2": "companyProperty2Type",
.
.
"companyPropertyN": "companyPropertyNType",
}
]
In order to achieve this kind of return type representation, you need to define your return type in remoteMethod options to be an array of the desired model.
为了实现这种返回类型表示,您需要在remoteMethod选项中将返回类型定义为所需模型的数组。
Here is your code, with the required edit, using modelName propery of Model base class:
这是您的代码,使用模型基类的modelName属性进行必需的编辑:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: [Company.modelName], root: true},
http: {path: '/', verb:'get'}
}
)
#1
3
If I understand you right, your'e trying to show at this section the returned model as follows:
如果我理解你的话,你试图在这一部分显示返回的模型如下:
[
{
"companyProperty1": "companyProperty1Type",
"companyProperty2": "companyProperty2Type",
.
.
"companyPropertyN": "companyPropertyNType",
}
]
In order to achieve this kind of return type representation, you need to define your return type in remoteMethod options to be an array of the desired model.
为了实现这种返回类型表示,您需要在remoteMethod选项中将返回类型定义为所需模型的数组。
Here is your code, with the required edit, using modelName propery of Model base class:
这是您的代码,使用模型基类的modelName属性进行必需的编辑:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: [Company.modelName], root: true},
http: {path: '/', verb:'get'}
}
)