1

我正在研究 rjsf 文档,我additionalItems对 array docs 的部分感到困惑。

以下是文档中的示例代码:

const Form = JSONSchemaForm.default;

const schema = {
  type: "array",
  items: {
    type: "string"
  },
  additionalItems: {
    type: "boolean"
  }
};

ReactDOM.render((
  <Form schema={schema} />
), document.getElementById("app"));

这是官方的codepen

如果删除 ,呈现的表单似乎表现完全相同additionalItems,那么目的是什么?我想它有一个,因为它在文档中明确提出,但我无法弄清楚:)

4

1 回答 1

2

additionalItems: <schema>用于指示如何处理超出您在架构中指定的枚举项目的项目,或者即使它们完全被允许。

在此模式中,第一个数组项必须是字符串,第二个必须是数字,但除此之外的任何其他项都是允许的,并且可以是任何内容:

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "number" }
  ]
}

在此模式中,第一项必须是字符串,第二项必须是数字,之后的所有项都必须是布尔值:

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "number" }
  ],
  "additionalItems": { "type": "boolean" }
}

在这个模式中,在前两个之后根本不允许有更多的项目:

{
  "type": "array",
  "items": [
    { "type": "string" },
    { "type": "number" }
  ],
  "additionalItems": false
}

您可以在文档中阅读有关此关键字的更多信息:https ://json-schema.org/understanding-json-schema/reference/array.html

于 2022-01-29T18:32:27.977 回答