Невозможно создать форму таблицы React с помощью react-jsonschema-form-extras

Я пытаюсь отобразить форму React в виде таблицы с помощью response-jsonschema-form-extras и получаю следующую ошибку:

"TypeError: Cannot read property 'tableCols' of undefined"

Я создаю форму React, используя react-jsonschema-form и react-jsonschema-form-extras. У меня все функции работают отлично, кроме "" ui: field ":" table "". См. документацию GitHub.

const schema = {
  "type": "object",
  "properties": {
    "listOfStrings": {
      "type": "array",
      "title": "A list of strings",
      "items": {
        "type": "string",
        "default": "bazinga"
      }
    }
  }
}

const uiSchema = {
  "listOfStrings": {
    "ui:field": "table"
  }
}

const formData = {
  "listOfStrings": [
    "foo",
    "bar"
  ]
}

Согласно документации, вы можете использовать таблицу без какой-либо дополнительной предопределенной конфигурации. Я также попытался определить столбец таблицы:

const uSchema = {
  "listOfStrings": {
    "ui:field": "table",
    "table": {
      "tableCols": [
        {
        "dataField": "listOfStrings"
        }
      ]
    }
  }
}

Приводит к следующей ошибке:

"TypeError: Cannot convert undefined or null to object"

person trd    schedule 01.07.2019    source источник


Ответы (1)


Вы неправильно определили схему. Элементы в объекте типа, в свою очередь, относятся к объекту типа, который имеет свойства того, как вы хотите, чтобы ваши атрибуты.

Песочница: https://codesandbox.io/s/silly-satoshi-jt4jw

--

const schema = {
  "type": "object",
  "properties": {
    "listOfStrings": {
      "type": "array",
      "title": "A list of strings",
      "items": {
       "type": "object",
        "properties": {
          string1: { type: "string", default: "bazinga" },
          string2: { type: "string" }
        }
      }
    }
  }
}

const uiSchema = {
  "listOfStrings": {
    "ui:field": "table"
  }
}

const formData = {
  "listOfStrings": [
    "foo",
    "bar"
  ]
}
person PragJh    schedule 16.11.2019