我尝试覆盖strongloop rest端点的 find api。我想返回一个对象数组。但是如何指定对象的架构?从上图中可以看出,模型架构为空。
以下是我公司型号remoteMethod的代码:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: 'array', root: true},
http: {path: '/', verb:'get'}
}
)
答案 0 :(得分:3)
如果我理解你的话,你试图在本节中显示返回的模型如下:
[
{
"companyProperty1": "companyProperty1Type",
"companyProperty2": "companyProperty2Type",
.
.
"companyPropertyN": "companyPropertyNType",
}
]
为了实现这种返回类型表示,您需要在remoteMethod选项中定义返回类型,使其成为所需模型的数组。
以下是您的代码,使用modelName propery of Model base class:
进行必要的修改Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: [Company.modelName], root: true},
http: {path: '/', verb:'get'}
}
)