简体   繁体   English

使用Firebase过滤列表后查询上的OrderByChild

[英]OrderByChild on a query after filtering list using Firebase

I have an Ionic mobile app that gets its data from a Firebase back end. 我有一个Ionic移动应用程序,可从Firebase后端获取其数据。 On one page I get a list of stations with location and current price for each station. 在一页上,我获得了一个电台列表,其中包含每个电台的位置和当前价格。 What I want to do is filter the list by location, and then order it by price. 我想做的是按位置过滤列表,然后按价格排序。

    let query = this.db.list('/stations', {
      query: {
        orderByChild: 'distanceFromUser',
        endAt: 50.0,
        limitToFirst: 20
      }
    });

    this.stations = query, {
      query: {
        orderByChild: 'currentPrice',
      }
    }

This code is obviously not working, but it kind of displays what I would like to accomplish. 这段代码显然无法正常工作,但是它显示了我想要完成的工作。 First create a query with the 20 closest stations in a 50 km radius, and then order this list by currentPrice. 首先使用半径为50 km的20个最近的电台创建查询,然后按currentPrice排序此列表。

Is there any way to make this happen with Firebase? 有什么办法可以使Firebase做到这一点?

You can try making a new child combining the two like distanceFromUser_currentPrice and then use it in the query. 您可以尝试结合像distanceFromUser_currentPrice这样的两个对象来制作一个新的子项,然后在查询中使用它。

Also, your query for finding 20 closest stations in a 50 km radius isn't gonna work because endAt will also return stations with distance like 150.0, 250.0 etc. 此外,您无法在50公里半径内查找20个最近的站点,因为endAt还会返回距离为150.0、250.0等的站点,因此无法执行查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM