如何在模式中添加对象列表(子)可选 Javascript(React-Native)
How add in schema a List of object(child) optional Javascript(React-Native)
非常感谢您。
我正在开发一个测验应用程序,它有两种类型的答案形式
,一种是多项选择选项
,另一种是开放式问题输入,然后在realm schema中我做了如下配置
选项架构(可选)
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 []'
模式中的可选因为它没有得到
阅读文档有以下情况:
属性
displayName: 'string?', // optional property
birthday: {type: 'date', optional: true}, // optional property
列表
testScores: 'double?[]'
尝试次数
在我的案例中尝试两种方式
先试试
options: {type: 'Option[]', optional: true},
第二次尝试
options:'Option?[]'
在这两种情况下都不起作用
你有解决办法吗?
一个不能解决问题但可能暂时有所帮助的选项是:
添加一条空记录,所有未注册的注册您都将空记录指向 child。
例子
架构选项
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;
图像 - 架构选项(children)
图片 - 模式问题(父亲)
谢谢大家我希望我能提供帮助,直到问题得到解决。
非常感谢您。
我正在开发一个测验应用程序,它有两种类型的答案形式
,一种是多项选择选项
,另一种是开放式问题输入,然后在realm schema中我做了如下配置
选项架构(可选)
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 []'
模式中的可选因为它没有得到
阅读文档有以下情况:
属性
displayName: 'string?', // optional property
birthday: {type: 'date', optional: true}, // optional property
列表
testScores: 'double?[]'
尝试次数
在我的案例中尝试两种方式
先试试
options: {type: 'Option[]', optional: true},
第二次尝试
options:'Option?[]'
在这两种情况下都不起作用 你有解决办法吗?
一个不能解决问题但可能暂时有所帮助的选项是:
添加一条空记录,所有未注册的注册您都将空记录指向 child。 例子
架构选项
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;
图像 - 架构选项(children)
图片 - 模式问题(父亲)
谢谢大家我希望我能提供帮助,直到问题得到解决。