我正在尝试将地图嵌套到RxJava2中的过滤器中,因此我可以删除所有没有正确平台的对象。但无法构建

问题描述 投票:0回答:1
override fun getVideoGamesRepository(platformName: String) {
    gameRepo = VideoGameRepositoryImpl()
    compositeDisposable.add(gameRepo.returnVideoGames()
        .filter { gameModel -> gameModel.gamesResults.map {  } }
        .subscribe())
}

这里是我从api过滤数据的方法。我将仅提供有关相关数据的摘录。

我正在尝试将数据库中平台名称的值与我在上一个活动中输入的平台名称进行比较。但是.map在过滤器内的.map处用红色下划线标出。

{
"count": 363773,
"next": "https://api.rawg.io/api/games?page=3",
"previous": "https://api.rawg.io/api/games",
"results": [
    {
        "id": 28,
        "slug": "red-dead-redemption-2",
        "name": "Red Dead Redemption 2",
        "released": "2018-10-26",
        "tba": false,
        "background_image": "https://media.rawg.io/media/games/511/5118aff5091cb3efec399c808f8c598f.jpg",
        "rating": 4.54,
        "rating_top": 5,
        "ratings": [
            {
                "id": 5,
                "title": "exceptional",
                "count": 1466,
                "percent": 70.28
            },
            {
                "id": 4,
                "title": "recommended",
                "count": 409,
                "percent": 19.61
            },
            {
                "id": 3,
                "title": "meh",
                "count": 143,
                "percent": 6.86
            },
            {
                "id": 1,
                "title": "skip",
                "count": 68,
                "percent": 3.26
            }
        ],
        "ratings_count": 2056,
        "reviews_text_count": 25,
        "added": 6296,
        "added_by_status": {
            "yet": 284,
            "owned": 3522,
            "beaten": 912,
            "toplay": 951,
            "dropped": 161,
            "playing": 466
        },
        "metacritic": null,
        "playtime": 22,
        "suggestions_count": 630,
        "user_game": null,
        "reviews_count": 2086,
        "saturated_color": "0f0f0f",
        "dominant_color": "0f0f0f",
        "platforms": [
            {
                "platform": {
                    "id": 4,
                    "name": "PC",
                    "slug": "pc",
                    "image": null,
                    "year_end": null,
                    "year_start": null,
                    "games_count": 203916,
                    "image_background": "https://media.rawg.io/media/games/8e0/8e032ac4faf1136e7d708bb3ac61af23.jpg"
                },
                "released_at": "2018-10-26",
                "requirements_en": null,
                "requirements_ru": null
            },
            {
                "platform": {
                    "id": 1,
                    "name": "Xbox One",
                    "slug": "xbox-one",
                    "image": null,
                    "year_end": null,
                    "year_start": null,
                    "games_count": 3085,
                    "image_background": "https://media.rawg.io/media/games/c24/c24ec439abf4a2e92f3429dfa83f7f94.jpg"
                },
                "released_at": "2018-10-26",
                "requirements_en": null,
                "requirements_ru": null
            },
            {
                "platform": {
                    "id": 18,
                    "name": "PlayStation 4",
                    "slug": "playstation4",
                    "image": null,
                    "year_end": null,
                    "year_start": null,
                    "games_count": 4504,
                    "image_background": "https://media.rawg.io/media/games/4be/4be6a6ad0364751a96229c56bf69be59.jpg"
                },
                "released_at": "2018-10-26",
                "requirements_en": null,
                "requirements_ru": null
            }
        ],
android kotlin rx-java
1个回答
0
投票

filter方法将filter作为参数。因此,您必须定义一个条件,该条件为您的过滤器返回true或false。

我正在尝试比较数据库中平台名称的值使用我在上一个活动中输入的平台名称

过滤器足以执行此操作。您不需要使用地图。试试这个:

predicate

此代码基本上过滤包含所需平台名称的游戏模型对象。

© www.soinside.com 2019 - 2024. All rights reserved.