Как добавить в схему список объектов (дочерних) необязательно Javascript (React-Native) - PullRequest
0 голосов
/ 08 января 2020

Заранее большое спасибо.
Я занимаюсь разработкой приложения для викторины с двумя типами ответов
с несколькими вариантами ответов варианты
и другим открытым вопросом введите , затем в схеме области я сделал следующую конфигурацию

Опционная схема (необязательно)

const OptionSchema = {
  name: 'Option',
  primaryKey: 'id',
  properties: {
    id: {type: 'int', indexed: true},
    description: 'string?',
    imageSound: 'string?',
    correct: 'bool',
    marked: 'bool?',
    play: 'bool?',
  },
};

export default OptionSchema;

Схема вопроса

const QuestionSchema = {
  name: 'Question',
  primaryKey: 'id',
  properties: {
    id: {type: 'int', indexed: true},
    questionForm: 'string',
    optionForm: 'string',
    typeAnswer: 'string',
    description: 'string',
    correctAnswerDescription: 'string?',
    correctAnswerDescriptionId: 'string?',
    imageSound: 'string?',
    options: 'Option?[]',
  },
};
export default QuestionSchema;

Вопрос

Мне было интересно, как мне оставить опции property: 'Option []' optiocinal в схеме, потому что она не читает документацию, есть следующие случаи:
для свойств

displayName: 'string?', // optional property
birthday:    {type: 'date', optional: true}, // optional property

для списка

testScores: 'double?[]'

Попытки

, пробуя оба способа в моем случае
первая попытка

options:    {type: 'Option[]', optional: true},

вторая попытка

options:'Option?[]'

ни в одном случае это не сработало бы у вас есть решение?

1 Ответ

0 голосов
/ 09 января 2020

Вариант, который не решает проблему, но может помочь временно:

добавить пустую запись, и во всех регистрациях, которые не зарегистрированы, вы указываете на ноль как ребенок. пример

Параметр схемы

const OptionSchema = {
  name: 'Option',
  primaryKey: 'id',
  properties: {
    id: {type: 'int', indexed: true, optional: true},
    description: {type: 'string', optional: true},
    imageSound: {type: 'string', optional: true},
    correct: {type: 'bool', optional: true},
    marked: {type: 'bool', optional: true},
    play: {type: 'bool', optional: true},
  },
};

export default OptionSchema;

Вопрос схемы

const QuestionSchema = {
  name: 'Question',
  primaryKey: 'id',
  properties: {
    id: {type: 'int', indexed: true},
    questionForm: 'string',
    optionForm: 'string',
    typeAnswer: 'string',
    description: 'string',
    correctAnswerDescription: {type: 'string', optional: true},
    correctAnswerDescriptionId: {type: 'int', optional: true},
    imageSound: {type: 'string', optional: true},
    options: 'Option[]',
  },
};
export default QuestionSchema;

Изображения - Параметр схемы (дочерние элементы)

enter image description here

Изображения - Вопрос схемы (отец)

enter image description here

Спасибо всем, надеюсь, я помог, пока проблема не найдет решение.

...