如何指定Strongloop模型架构? [英] How to specify Strongloop model schema?

查看:93
本文介绍了如何指定Strongloop模型架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试覆盖Strongloop Rest端点的 find API.我想返回一个对象数组.但是,如何指定对象的架构?从上图可以看到,模型架构为空.

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.

下面是我公司模型remoteMethod的代码:

Below is the code of my company model remoteMethod:

    Company.remoteMethod(
        'find',
        {
            accepts: {arg: 'msg', type: 'string'},
            returns: {type: 'array', root: true},
            http: {path: '/', verb:'get'}
        }
    )

推荐答案

如果我理解的正确,您正在尝试在此部分显示返回的模型,如下所示:

If I understand you right, your'e trying to show at this section the returned model as follows:

[
  {
    "companyProperty1": "companyProperty1Type",
    "companyProperty2": "companyProperty2Type",
    .
    .
    "companyPropertyN": "companyPropertyNType",
  }
]

为了实现这种返回类型表示,您需要在remoteMethod选项中定义返回类型,以使其成为所需模型的数组.

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.

这是您的代码,使用 modelName进行了必要的编辑模型基类的属性:

Company.remoteMethod(
    'find',
    {
        accepts: {arg: 'msg', type: 'string'},
        returns: {type: [Company.modelName], root: true},
        http: {path: '/', verb:'get'}
    }
)

这篇关于如何指定Strongloop模型架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆