Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native Realm React Native:如何从对象';带条件的s嵌套数组_React Native_Realm_Realm Mobile Platform - Fatal编程技术网

React native Realm React Native:如何从对象';带条件的s嵌套数组

React native Realm React Native:如何从对象';带条件的s嵌套数组,react-native,realm,realm-mobile-platform,React Native,Realm,Realm Mobile Platform,我是React native的新手,尝试将Realm集成为客户端数据库。 我有两个模式: export const CAR_SCHEMA = { name: 'Car', properties: { color: 'string', model: 'string', } }; export const PERSONS_SCHEMA = { name: 'Person', primaryKey: 'id', properties: { id: 'i

我是React native的新手,尝试将Realm集成为客户端数据库。 我有两个模式:

export const CAR_SCHEMA = {
  name: 'Car',
  properties: {
    color: 'string',
    model: 'string',
  }
};

export const PERSONS_SCHEMA = {
  name: 'Person',
  primaryKey: 'id',
  properties: {
    id: 'int',
    firstName: 'string',
    lastName: 'string'
    cars: 'Cars[]'
  }
};

我的问题基本上是指如何将“车”从车所在的“人”中删除。model='Honda'?我找不到任何关于从对象的嵌套数组中删除元素的文档。

从数组中删除,但将项保留在域中:

realm.write(() => {
    let person = realm.objectForPrimaryKey('person', personId);
    let carsOfPerson = person.cars;

    var i = carsOfPerson.length - 1;
    while(i >= 0) {
        if(carsOfPerson[i].model == "Honda") {
            carsOfPerson.splice(i, 1);
        }
        i--;
    }
});
通过从域中删除项从数组中删除:

realm.write(() => {
    let person = realm.objectForPrimaryKey('person', personId);
    let carsOfPerson = person.cars;
    let hondasOfPerson = carsOfPerson.filtered('model = "HONDA"')
    realm.delete(hondasOfPerson)
});

从数组中删除但将项保留在域中:

realm.write(() => {
    let person = realm.objectForPrimaryKey('person', personId);
    let carsOfPerson = person.cars;

    var i = carsOfPerson.length - 1;
    while(i >= 0) {
        if(carsOfPerson[i].model == "Honda") {
            carsOfPerson.splice(i, 1);
        }
        i--;
    }
});
通过从域中删除项从数组中删除:

realm.write(() => {
    let person = realm.objectForPrimaryKey('person', personId);
    let carsOfPerson = person.cars;
    let hondasOfPerson = carsOfPerson.filtered('model = "HONDA"')
    realm.delete(hondasOfPerson)
});

@阿森·亚历山扬,这个答案对你很有用….?我似乎已经回答了这个问题@阿森·亚历山扬,这个答案对你很有用….?我似乎已经回答了这个问题。。。