Android returns 空对象上的 React-Native Realm,在 iOS 上工作正常
React-Native Realm on Android returns empty objects, works fine on iOS
我们的 react-native (0.62.0) 和 realm (5.0.2) 部署存在以下问题:
我们有一个包含几个模型的架构,其中一个是 Location
。我们可以在两个设备(ios 和 android)上插入位置,但是,当我们想从中检索对象时,它只适用于 ios.
{
name: 'Location',
primaryKey: 'uuid',
properties: {
uuid: {type: 'string', indexed: true},
id: {type: 'int'},
title: 'string?',
latitude: 'float?',
longitude: 'float?',
latitudedelta: 'float?',
longitudedelta: 'float?',
radius: 'float?',
},
},
我们执行以下操作来访问我们的领域:
let repository = new Realm({schema:[{
name: 'Location',..see above..}]});
export const LocationService = {
findAll: function(sortBy) {
let results = repository.objects('Location');
console.log('LocationService.findAll', results);
return results;
},
};
当使用 iOS 时,我们有以下 console.log:
LocationService.findAll {"0": {"id": 11, "latitude": 53.160179138183594, "latitudedelta": 0, "longitude": 10.146489143371582, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "16e1b034-f4b9-44d8-9f58-e30de82dd346"}, "1": {"id": 1, "latitude": 40.732025146484375, "latitudedelta": 0, "longitude": -74.00248718261719, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "ada51419-eea0-45ef-8209-581ce083a4fc"}, "2": {"id": 2, "latitude": 51.5080680847168, "latitudedelta": 0.2786773443222046, "longitude": -0.13921460509300232, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "4311470f-d790-4c40-a2b1-f210b723fa08"}, "3": {"id": 12, "latitude": 53.76025390625, "latitudedelta": 0, "longitude": 9.679306983947754, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "82b40618-051d-49b3-9281-334796e5660c"}}
与 Android 一样,我们得到以下 console.log:
LocationService.findAll {"0": {}}
稍后在代码中我们强制访问 id,例如:
let loadedLocations = LocationService.findAll();
loadedLocations.forEach(l => {
console.log(l.id);
});
同样,在 iOS 上我们得到带有 ID 的 console.log 输出,而在 android 上我们只看到未定义的。
在真实设备上附加调试器并在控制台中检查时,我们还可以在结果输出中看到更多信息:
有趣的是,在模式中的其他模型上,我们在 Android 上没有这个问题。 android 完美加载其他模型。在 location 的情况下,它确实看到了 realm 实例中有一个条目,当我们从设备(模拟器 && 真实测试设备)下载 .realm 文件时,我们可以看到条目是正确的!
可能是什么问题,仅在此模型上,仅在获取对象上,仅在 android 上我们 运行 遇到此问题?
将领域更新到版本 5.0.3
realm js 5.0.2 有一个错误 https://github.com/realm/realm-js/releases/tag/v5.0.3
我们的 react-native (0.62.0) 和 realm (5.0.2) 部署存在以下问题:
我们有一个包含几个模型的架构,其中一个是 Location
。我们可以在两个设备(ios 和 android)上插入位置,但是,当我们想从中检索对象时,它只适用于 ios.
{
name: 'Location',
primaryKey: 'uuid',
properties: {
uuid: {type: 'string', indexed: true},
id: {type: 'int'},
title: 'string?',
latitude: 'float?',
longitude: 'float?',
latitudedelta: 'float?',
longitudedelta: 'float?',
radius: 'float?',
},
},
我们执行以下操作来访问我们的领域:
let repository = new Realm({schema:[{
name: 'Location',..see above..}]});
export const LocationService = {
findAll: function(sortBy) {
let results = repository.objects('Location');
console.log('LocationService.findAll', results);
return results;
},
};
当使用 iOS 时,我们有以下 console.log:
LocationService.findAll {"0": {"id": 11, "latitude": 53.160179138183594, "latitudedelta": 0, "longitude": 10.146489143371582, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "16e1b034-f4b9-44d8-9f58-e30de82dd346"}, "1": {"id": 1, "latitude": 40.732025146484375, "latitudedelta": 0, "longitude": -74.00248718261719, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "ada51419-eea0-45ef-8209-581ce083a4fc"}, "2": {"id": 2, "latitude": 51.5080680847168, "latitudedelta": 0.2786773443222046, "longitude": -0.13921460509300232, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "4311470f-d790-4c40-a2b1-f210b723fa08"}, "3": {"id": 12, "latitude": 53.76025390625, "latitudedelta": 0, "longitude": 9.679306983947754, "longitudedelta": 0.08983111381530762, "radius": 35, "title": "", "uuid": "82b40618-051d-49b3-9281-334796e5660c"}}
与 Android 一样,我们得到以下 console.log:
LocationService.findAll {"0": {}}
稍后在代码中我们强制访问 id,例如:
let loadedLocations = LocationService.findAll();
loadedLocations.forEach(l => {
console.log(l.id);
});
同样,在 iOS 上我们得到带有 ID 的 console.log 输出,而在 android 上我们只看到未定义的。
在真实设备上附加调试器并在控制台中检查时,我们还可以在结果输出中看到更多信息:
有趣的是,在模式中的其他模型上,我们在 Android 上没有这个问题。 android 完美加载其他模型。在 location 的情况下,它确实看到了 realm 实例中有一个条目,当我们从设备(模拟器 && 真实测试设备)下载 .realm 文件时,我们可以看到条目是正确的!
可能是什么问题,仅在此模型上,仅在获取对象上,仅在 android 上我们 运行 遇到此问题?
将领域更新到版本 5.0.3
realm js 5.0.2 有一个错误 https://github.com/realm/realm-js/releases/tag/v5.0.3