不调试时我无法获得任何查询的结果,但在调试时可以完美运行
此外,我注意到 Realm 的行为根据凋谢调试与否有很大不同
这只是这个想法的总结:
我正在打印object.constructor.name
以查找对象的类型
调试时(远程使用 Chrome 或 Safari):
let realm = new Realm(config);
realm.constructor.name --> will print (Realm)
let dogs = realm2.objects('Dog');
dogs.constructor.name --> will print (Results)
(inserting few dogs)
for (let oneDog of dogs) {
oneDog.constructor.name --> will print (RealmObject)
} --> works perfectly
但是当不调试时,一切都不同了:
let realm = new Realm(config);
realm.constructor.name --> will print (Object)
let dogs = realm2.objects('Dog');
dogs.constructor.name --> will print nothing
(inserting few dogs)
for (let oneDog of dogs) {
oneDog.constructor.name --> not compiled
} --> will give the error below
TypeError: undefined is not a function (evaluating ‘_iterator[typeof
Symbol === “function” ? Symbol.iterator : “@@iterator”]()')
我不确定这是我的代码的错误还是问题
领域和工具的版本
- Realm JS SDK 版本:2.10.0
- 反应原生:0.55.4
- 客户端操作系统和版本:在 Android 设备 8.0 上运行
- React Native 的调试器:Chrome
完整代码:
import React, { Component } from 'react';
import { View, Text } from 'react-native';
const Realm = require('realm');
export default class Page3Screen extends Component {
state = { messege : 'no messege' }
componentWillMount() {
const config = {
schema: [{ name: 'Dog', properties: { name: 'string' } }],
};
let realm = new Realm(config);
console.log(realm.constructor.name);
this.setState({ messege: realm.constructor.name });
realm.write(() => {
realm.create('Dog', { name: 'Zozo' });
});
let dogs = realm.objects('Dog');
// console.log(dogs.constructor.name);
// this.setState({ messege: dogs.constructor.name });
// for (let oneDog of dogs) {
// console.log(oneDog.constructor.name);
// this.setState({ messege: oneDog.constructor.name });
// }
}
render() {
return (
<View style={{ alignSelf: 'stretch', flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>{this.state.messege}</Text>
</View>
);
}
}