我正在尝试使用我的本机应用程序本地设置Realm DB,但似乎有一个错误,我无法找出原因.我遵循了
documentation和指南
here.
我的代码.
import Realm from 'realm'; export const ConfigSchema = { name: 'Config',primaryKey: 'key',properties: { key: 'string',value: 'string' } }; export const databaSEOptions = { path: 'myappreactnative.realm',schema: [ConfigSchema],schemaVersion: 0 }; export const insertNewConfig = (newConfig) => new Promise((resolve,reject) => { Realm.open(databaSEOptions).then(realm => { // realm.create('Config',newConfig); // resolve(newConfig); console.log(realm); }).catch((error) => reject(error)) });
我从这里调用insertNewConfig,
let config = { key: 'instanceUrl',value: 'myurl.domain.value' }; insertNewConfig(config).then((result) => { console.log(result); }).catch((error) => { console.log(error); }); this.props.navigation.navigate('Login',{});
错误出现在Realm.open(databaSEOptions)行.首先我虽然错误是在realm.create但后来实现了原始行.
Error: _constructor must be of type 'function',got (undefined) at sendRequest (rpc.js:263) at Object.createRealm (rpc.js:62) at new Realm (index.js:102) at Function.open (extensions.js:110) at eval (eval at <anonymous> (MetroClient.js:63),<anonymous>:29:22) at tryCallTwo (core.js:45) at doResolve (core.js:200) at new Promise (core.js:66) at insertNewConfig (eval at <anonymous> (MetroClient.js:63),<anonymous>:28:12) at Object.SelectInstanceScreen._this.continueLogin [as onPress] (eval at <anonymous> (MetroClient.js:63),<anonymous>:74:37)
似乎open()函数必须作为函数调用(_constructor必须是’function’类型),但很明显open()作为函数调用.
提前致谢.
我想也许是最后一个版本(2.18.0)上的一个错误,尝试降级到2.16.0它会起作用.
原文链接:https://www.f2er.com/react/301033.html