FireBase筛选节点基于组合键值

时间:2018-03-06 00:39:31

标签: firebase firebase-realtime-database

我有一个firebase节点,如下所示

"accountEntries": {
"records" : {
    "-L6sVLAzVjPp7EU5FuWh" : {
       "filters" : {
        "-L6sVLB3Ko76l9xRDYRI" : "02-11-2018",
        "-L6sVLB4i-UCsJnUboIH" : "Second Customer",
        "-L6sVLB5EGGO9cl2h_K4" : "02-11-2018_Second Customer",
        "-L6sVLB7wevrdWLcVgDY" : "02-11-2018_Second Customer_cash",
        "-L6sVLB8ElLJRSPEbvEs" : "Second Customer_cash",
        "-L6sVLB9nBnVUtYQKoL8" : "cash",
        "-L6sVLBA8vZhSixrw73J" : "02-11-2018_cash"
      }
    },
    "-L6sVMFYOdIPIjhekxy0" : {
      "filters" : {
        "-L6sVMFcWR7Y6ADmSFrJ" : "02-14-2018",
        "-L6sVMFeGGxMbYLpQaim" : "Fourth Customer",
        "-L6sVMFhLbF_zF9b_rgl" : "02-14-2018_Fourth Customer",
        "-L6sVMFj4dW6pKQZVTR9" : "02-14-2018_Fourth Customer_cash",
        "-L6sVMFmB2iFC53TSYyE" : "Fourth Customer_cash",
        "-L6sVMFoYEE_MSPzrSHA" : "cash",
        "-L6sVMFq09fn2rqn3vV4" : "02-14-2018_cash"
      }
    },
    "-L6sVMy374a07w018-lT" : {
      "filters" : {
        "-L6sVMy857VluJe6G7-8" : "02-18-2018",
        "-L6sVMy9j_fIL9xJqfGq" : "Fourth Customer",
        "-L6sVMyBkPcpxS9CQev3" : "02-18-2018_Fourth Customer",
        "-L6sVMyDFlpMfvpD4Wbv" : "02-18-2018_Fourth Customer_cash",
        "-L6sVMyEKN3rnfptc24c" : "Fourth Customer_cash",
        "-L6sVMyHG0F2IMQVI9TY" : "cash",
        "-L6sVMyKj6I8i-idICE8" : "02-18-2018_cash"
      }
    },
    "-L6sVNmDGKqTJN7XsZmI" : {
      "filters" : {
        "-L6sVNmHZCeYtEBI_Vok" : "02-19-2018",
        "-L6sVNmIoR53aqW6Um0S" : "Fourth Customer",
        "-L6sVNmKk3PMAwrMYsPl" : "02-19-2018_Fourth Customer",
        "-L6sVNmMg9trmWeOBhSg" : "02-19-2018_Fourth Customer_cash",
        "-L6sVNmOQUuYMWWuxNnV" : "Fourth Customer_cash",
        "-L6sVNmRFoomegzHyi5_" : "cash",
        "-L6sVNmUzFjyShhJPDTa" : "02-19-2018_cash"
      }
    }
  }
}

目标是根据具有不同组合的过滤器节点过滤记录。

我们有三个过滤器日期,客户名称和类型

如果我们想要过滤日期,那么将使用

检查过滤器值
startAt('02-19-2018).endAt('02-19-2018')

如果我们想要过滤客户,那么将使用

检查过滤器值
startAt('Fourth Customer').endAt('Fourth Customer')

如果我们想要对类型进行过滤,那么将使用

检查过滤器值
startAt('cash').endAt('cash')

如果我们想过滤日期和客户,那么将检查过滤器值,日期范围= 02-11-2018到02-18-2018,客户="第二客户","第四位客户"

startAt('02-11-2018_Second Customer').endAt('02-18-2018_Fourth Customer')

我的firebase代码如下所示。

var startfilterKey="02-11-2018_Second Customer";
var endfilterKey = "02-18-2018_Fourth Customer";

var accountEntriesList= this.firebase.database.ref('/accountEntries/records').orderByChild('filters').startAt(startfilterKey).endAt(endfilterKey).limitToLast(10);

accountEntriesList.once('value',function(snapshot) { 
  if(snapshot){
     snapshot.forEach(childShapshot => {
     var key = childShapshot.key;
     accountEntriesKeyValue.push(key);
     return false;
  });
 }
});

上述代码不能按预期过滤节点。

如果我删除了endAt,它会给出所有节点。

如何根据过滤器组合键过滤节点?

0 个答案:

没有答案