遵循https://github.com/realm/realm-js/blob/master/examples/ReactExample/components/realm.js中的示例:
realm.js:
import Realm from 'realm';
class Todo extends Realm.Object {}
Todo.schema = {
name: 'Todo',
properties: {
done: {type: 'bool', default: false},
text: 'string',
},
};
class TodoList extends Realm.Object {}
TodoList.schema = {
name: 'TodoList',
properties: {
name: 'string',
creationDate: 'date',
items: {type: 'list', objectType: 'Todo'},
},
};
export default new Realm({schema: [Todo, TodoList]});
App.js:
import realm from './realm';
但是我得到这个错误:
null is not an object (evaluating '_NativeModules$Realm.debugHosts')
<unknown>
答案 0 :(得分:0)
您最好使用对象,而不是类。
const Realm = require('realm');
const Todo = {
name: 'Todo',
properties: {
done: {type: 'bool', default: false},
text: 'string',
},
};
const TodoList = {
name: 'TodoList',
properties: {
name: 'string',
creationDate: 'date',
items: {type: 'list', objectType: 'Todo'},
},
};
const newRealm = Realm.open({schema: [Todo, TodoList]})
export default newRealm;