且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Loopback explorer中隐藏'id'属性?

更新时间:2023-02-15 15:45:45

按顺序隐藏'id'属性,您需要将此字段声明为隐藏。

In order to hide the 'id' attribute, you need declare this field as hidden.

在YOUR_MODEL.json文件中:

In YOUR_MODEL.json file:

{
  "name": "YOUR_MODEL",
  .
  .
  .
  "properties": {
     // your custom properties
  },
  "hidden": ["id"], // this attribute specifies which attributes need to be hidden
  .
  .
  .
}

当一个属性被声明为隐藏时,请注意:

Be aware when a property declared as hidden:


  1. 未向用户公开

  2. 虽然隐藏,但如果用户发送提供此属性的值,属性默认情况下不会被忽略,并将使用提供的值进行处理。因此,需要手动忽略。

  1. It's not exposed to the user
  2. Although hidden, if user sends provides a value with this property, the property won't be ignored by default, and will be handled with provided values. hence, need to be ignored manually.

例如,如果我们有'User'模型如下:

For instance, if we have 'User' model as follows:

{
  "name": "User",
  .
  .
  .
  "properties": {
     "id": "string",
     "name": "string",
     "password": "string",

  },
  "hidden": ["id", "password"],
  .
  .
}

/ api / User GET请求将提供具有仅'name'属性的用户列表

/api/User GET request will provide list of Users with only 'name' attribute

/ api / User POST with body:

BUT, /api/User POST with body:

{
  "user" : "USER",
  "password": "PASS",
  "id" : "USER_PROVIDED_ID"
}

正文中提供的用户将使用其中的值进行保存。

the user provided in the body will be saved with the values in it.