代码之家  ›  专栏  ›  技术社区  ›  FabricioG

值为的Firebase筛选器

  •  0
  • FabricioG  · 技术社区  · 5 年前

    fDB.ref(`organization/${uid}/attendance/${date}`)
    .once('value')
    .then(d => console.log(d.val()))
    

    返回如下对象:

    { '-Lz8YxH_n7a5C6wv5vrX': 'absent',
      '-Lz8YxHbn5iOCxaGUBZt': 'absent',
      '-Lz8YxHfQPKH5BaIJBK_': 'absent',
      '-Lz8YxHiwp8QZW3TqAFn': 'present',
      '-Lz8YxHjtMUkroeyT5bv': 'absent',
      '-Lz8YxHmHqDblmBY4jyx': 'absent',
      '-Lz8YxHo-e4AiOwwex0s': 'absent',
      '-Lz8YxHqQXWoaGOFRLrO': 'present',
    }
    

    如何只查询不存在的值? 我试过:

    fDB.ref(`organization/${uid}/attendance/`)
        .orderByChild(date)
        .equalTo('absent')
        .once('value')
        .then(d => console.log(d.val()))
    

    我也试过了

    fDB.ref(`organization/${uid}/attendance/${date}`)
        .orderByKey()
        .equalTo('absent')
        .once('value')
        .then(d => console.log(d.val()))
    

    同样的东西是空的。我怎样才能做到?

    0 回复  |  直到 5 年前
        1
  •  1
  •   Umar Hussain    5 年前

    它会过滤掉 orderByValue equalTo ,允许您在值中运行筛选器:

     fDB.ref(`organization/${uid}/attendance/${date}`)
        .orderByValue()
        .equalTo('absent')
        .once('value')
        .then(d => console.log(d.val()));
    
    推荐文章