reactjs 如何在React Native Realm中过滤嵌套模式?

oyxsuwqo  于 2023-03-12  发布在  React
关注(0)|答案(1)|浏览(122)

我是新领域的新手。我如何在React Native Realm中过滤嵌套模式?我正在尝试使用Realm查询。我已经可以用javascript处理这个问题了。
型号:

const ModelA = {
    name: "ModelA",
    primaryKey: "id",
    properties: {
        id: "objectId",
        name: "string",
        data: "ModelB[]"
    }
};

const ModelB = {
    name: "ModelB",
    properties: {
        label: "int",
        text: "string"
    }
};

我有这样的数据。

[
    {
        "id": "6407d4949096750f578c536c",
        "name": "name1",
        "data": [
            { "label": "1", "text": "text1" },
            { "label": "1", "text": "text2" },
            { "label": "2", "text": "text3" },
            { "label": "2", "text": "text4" },
        ]
    },
    {
        "id": "7407d4949096750f578c536c",
        "name": "name2",
        "data": [
            { "label": "1", "text": "text1" },
            { "label": "2", "text": "text2" },
            { "label": "2", "text": "text3" },
            { "label": "2", "text": "text4" },
        ]
    }
]

这里我想要过滤和列表,比如label == 1,就像这个例子一样,我该怎么做呢?

[
    {
        "id": "6407d4949096750f578c536c",
        "name": "name1",
        "data": [
            { "label": "1", "text": "text1" },
            { "label": "1", "text": "text2" },
        ]
    },
    {
        "id": "7407d4949096750f578c536c",
        "name": "name2",
        "data": [
            { "label": "1", "text": "text1" },
        ]
    },
]
hjzp0vay

hjzp0vay1#

遵循文档和tutorial-query-language
你应该可以用filtered过滤它。
这就像:

const filterData = realm.objects('Model');
const result = filterData.filtered( 'label == $0',  '1');

相关问题