【发布时间】:2016-07-06 00:56:46
【问题描述】:
我正在尝试创建具有 json 对象数组和嵌套对象数组的 Realm 数据库。
当我尝试使用下面的代码添加时,我总是得到错误:JS value must be of type: object.
架构:
import Realm from 'realm';
class Exercise extends Realm.Object {
}
Exercise.schema = {
name: 'Exercise',
primaryKey: 'id',
properties: {
id: 'int',
name: 'string',
category: 'string',
bodyPart: 'string',
levels: {type: 'list', objectType: 'Level'}
}
};
class Level extends Realm.Object {
}
Level.schema = {
name: 'Level',
properties: {
level: 'int',
equipments: 'string'
}
};
export default new Realm({schema: [Exercise, Level, Multiplier]});
以及我尝试创建数据库的方法:
realm.write(() => {
let exercise = realm.create('Exercise', {
id: 209,
name: 'Dumbbell Overhead Press',
category: 'Military Press',
bodyPart: 'Shoulder'
}, true);
exercise.levels.push({
level: 3,
equipments: 'DB'
});
});
我尝试了所有可能的方法,将数组直接放在练习创建等中,我没有成功..
干杯
【问题讨论】:
标签: javascript json react-native realm realm-list