如何对Firebase数据库子项进行排序?

时间:2016-12-15 20:18:23

标签: android firebase firebase-realtime-database

我想选择所有类别时尚的节点,请给我一个方法,怎么做?

以下是我正在尝试的代码,但它无效:

databaseRef.child("All");
    databaseRef.orderByChild("category").equalTo("Fashion");
    databaseRef.addChildEventListener(new ChildEventListener() {...}

这是一个JSON数据。

{
  "-KZ23rvePtICBnQ_0eh-" : {
    "category" : "Fashion",
    "description" : "",
    "link" : "",
    "name" : "abof"
  },
  "-KZ2PgVpI-R60ZuFSnS2" : {
    "category" : "Fashion",
    "description" : " and answer",
    "link" : "fhhggh",
    "name" : "Amazon"
  },
  "-KZ2QayVvfZ6MN6V6Xhm" : {
    "category" : "Fashion",
    "description" : "get  50 % off on top brands",
    "link" : "wwe.abof.com",
    "name" : "abof"
  },
  "-KZ2Qj4XA2FWZm3V46TM" : {
    "category" : "Fashion",
    "description" : "",
    "link" : "www.myntra.com",
    "name" : "Myntra"
  },
  "-KZ2QrklT7cTCZMjmqZi" : {
    "category" : "Travels",
    "description" : "",
    "link" : "www.olacab.com",
    "name" : "Ola"
  },
  "-KZ2RZ5E5dt1GxRzuo37" : {
    "category" : "Travels",
    "description" : "get off on today's ride",
    "link" : "www.makemytrip.com",
    "name" : "MakeMyTrip"
  },
  "-KZ2RiM8fdYYa0e9yceR" : {
    "category" : "Travels",
    "description" : "free ride up to 50 km",
    "link" : "www.uber.com",
    "name" : "Uber"
  },
  "-KZ2S3kTGXfA014r7Bu1" : {
    "category" : "Food",
    "description" : "buy one get one free",
    "link" : "www.burgering.com",
    "name" : "Burgerking"
  },
  "-KZ2SL6DyCQ791kMO4jW" : {
    "category" : "Food",
    "description" : "flat 60% off only today",
    "link" : "www.kfc.com",
    "name" : "KFC"
  },
  "-KZ2SX3k5bq36alQ_V_c" : {
    "category" : "Recharge",
    "description" : "cash back offer",
    "link" : "www.paytm.com",
    "name" : "Paytm"
  },
  "-KZ2SfuH8x8Ifp1kh3cW" : {
    "category" : "Recharge",
    "description" : "get cash back",
    "link" : "www.mibokwik.com",
    "name" : "MoboKwik"
  },
  "-KZ2SvnogJ-iFYrkCzAu" : {
    "category" : "Mobiles",
    "description" : "get 20% off on order above 6000",
    "link" : "www.flipkart.com",
    "name" : "Flipkart"
  },
  "-KZ2T9XwueMaqN9hx65g" : {
    "category" : "Mobiles",
    "description" : "flat 20% off",
    "link" : "www.flipkart.com",
    "name" : "Amazon"
  },
  "-KZ2TTDrahu-XCaS7BkI" : {
    "category" : "Movies",
    "description" : "get off on today's show. ",
    "link" : "www.paytm.com",
    "name" : "Paytm"
  }
}

1 个答案:

答案 0 :(得分:2)

您需要将这些请求链接起来。例如,

    databaseRef.child("All").orderByChild("category").equalTo("Fashion").addChildEventListener(new ChildEventListener() {
    }