如何使用 React Mozilla 表单创建一个复选框数组?

How to create an array of checkboxes using React Mozilla forms?

我正在尝试使用 https://github.com/mozilla-services/react-jsonschema-form

制作表格

与此类似example,但在这里我试图制作一个状态数组。

我在创建 jsonschema 时严重失败。

我的示例 json 相同的模式是

const schema = {
    type:'object',
  properties:{
    'states':{
          'type':'array',
         items: {
        type: "object",
        properties: {
          description: {
            "type": "string"
          }
        }
      }
    }
  }

}

这应该有效:

const schema = {
    "type":"object",
    "properties":{
        "states":{
            "type":'array',
            "items": {
             "type": "number",
             "enum": [1,2,3],
             "enumNames":["New York","California","Dallas"]
            }
        },
        "uniqueItems": true
    }
}

const uiSchema = {
    "states": {
        "ui:widget": "checkboxes"
    }
}

如果 uniqueItems 存在,这将呈现一个复选框列表。

Fiddle 这里 - https://jsfiddle.net/r7otypfp/ Link 至 docs

希望对您有所帮助。