如何指定 Strongloop 模型架构?
How to specify Strongloop model schema?
我尝试覆盖 find api strongloop 休息端点。我想要 return 一个对象数组。但是如何指定对象的模式呢?从上图可以看出,模型模式是空的。
下面是我公司模型remoteMethod的代码:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: 'array', root: true},
http: {path: '/', verb:'get'}
}
)
如果我没理解错的话,您正试图在此部分显示 returned 模型,如下所示:
[
{
"companyProperty1": "companyProperty1Type",
"companyProperty2": "companyProperty2Type",
.
.
"companyPropertyN": "companyPropertyNType",
}
]
为了实现这种 return 类型表示,您需要在 remoteMethod options 中定义您的 return 类型为一个数组想要的型号。
这是您的代码,经过必要的编辑,使用 modelName propery of Model base class:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: [Company.modelName], root: true},
http: {path: '/', verb:'get'}
}
)
我尝试覆盖 find api strongloop 休息端点。我想要 return 一个对象数组。但是如何指定对象的模式呢?从上图可以看出,模型模式是空的。
下面是我公司模型remoteMethod的代码:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: 'array', root: true},
http: {path: '/', verb:'get'}
}
)
如果我没理解错的话,您正试图在此部分显示 returned 模型,如下所示:
[
{
"companyProperty1": "companyProperty1Type",
"companyProperty2": "companyProperty2Type",
.
.
"companyPropertyN": "companyPropertyNType",
}
]
为了实现这种 return 类型表示,您需要在 remoteMethod options 中定义您的 return 类型为一个数组想要的型号。
这是您的代码,经过必要的编辑,使用 modelName propery of Model base class:
Company.remoteMethod(
'find',
{
accepts: {arg: 'msg', type: 'string'},
returns: {type: [Company.modelName], root: true},
http: {path: '/', verb:'get'}
}
)