【发布时间】:2017-01-06 15:27:04
【问题描述】:
我正在使用 react native 开发应用程序,我需要删除在过滤方法中给我的特定对象,但它给了我一个名为
的错误“只能删除事务中的对象。”
这是我的代码
allObj1 = {
id : 1,
speed : "1",
accuracy: "100",
bearing: "1",
longitude: "192",
altitude: "1111",
latitude: "1111",
time: "11111",
locationProvider: "2222",
};
allObj2 = {
id : 2,
speed : "1",
accuracy: "100",
bearing: "1",
longitude: "192",
altitude: "1111",
latitude: "1111",
time: "22222",
locationProvider: "2222",
};
allObj3 = {
id : 3,
speed : "1",
accuracy: "100",
bearing: "1",
longitude: "192",
altitude: "1111",
latitude: "1111",
time: "333333",
locationProvider: "2222",
};
realm.write(() => {
realm.create('Location',allObj1 );
//realm.delete(firstObj);
realm.create('Location',allObj2 );
realm.create('Location',allObj3 );
});
let locationO = realm.objects('Location');
//let tanlocation = locationO.filtered('id >1 AND id <3 ');
// Observe Collection Notifications
realm.objects('Location').filtered('id >=1 AND id <=3').addListener((tanlocation, changes) => {
try{
tanlocation.forEach((realmObj,index) => {
realm.delete(realmObj);
});
}
catch(err){
console.log(err);
}
});
// Unregister all listeners
realm.removeAllListeners();
//realm.delete(tanlocation);
//console.log( tanlocation );
console.log(locationO);
它向我抛出了一个名为“只能删除事务中的对象”的错误。
有人遇到过这种问题吗?任何人都知道如何修复此方法或替代方法以实现上述功能
【问题讨论】:
标签: react-native realm