【发布时间】:2026-01-30 20:30:01
【问题描述】:
我正在尝试在 react-native 中使用 realm-js,所以我所做的是在我的操作文件夹中创建了一个 realm-js 类,就像在 中一样LoginActions.js,用户登录后写入数据。
我的问题是如何将相同的架构打开到另一个 .js 文件中?
在 LoginActions.js 中定义的 Realm-js:
class Login {
get token() {
return this.token;
}
}
Login.schema = {
name: 'Login',
primaryKey: 'id',
properties: {
id: 'int',
token: 'string',
}
};
然后我用我的一些函数在这个模式中打开要写入和更新的领域。
喜欢:
// If Login User Success
Realm.open({ schema: [Login] })
.then(realm => {
realm.write(() => {
realm.create('Login', { id: 1, token });
});
});
现在如果想将此架构打开到另一个 .js 文件中。我将如何打开它? 我想要的主要格式就像在 Loading.js 中一样:
import ????? from ????;
或
Realm.open(????????)
.then(realm => {
realm.write(() => {
const isUser = realm.create('Login', { id: 1, token }, true);
if(isUser.length == 1) {
// User Logs In Directly to Main Screen
} else {
// Show them Login Screen
}
});
});
【问题讨论】:
-
您找到问题的答案了吗?
标签: node.js react-native realm