Firebase查询随机生成的密钥中包含的十六进制代码 [英] Firebase query hex codes contained within randomly generated keys

查看:177
本文介绍了Firebase查询随机生成的密钥中包含的十六进制代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从颜色十六进制数组中查询一个特定的孩子。



下面是我的数据库结构的快照:



如何查询特定的十六进制代码并获取其父对象的整个数组?

解决方案

您无法查询列表中是否存在特定的值。这是Firebase文档建议不要在数据库中使用数组的原因之一。



但是在这种情况下(以及遇到的大多数情况),您可能会并不需要一个数组。说你只关心你的用户选择了什么颜色。在这种情况下,您可以更有效地将颜色存储为 set
$ b

  palettes 
-KSmJZ .... A5I
0x474A39:true
0xbA9A7C:true
0xDEDEDF:true
0x141414:true
0x323E35 :true


I would like to query a particular child from the array of color hex codes.

Here's a snapshot of my database structure:

How do I query a particular hex code and obtain the entire array of its parent object?

解决方案

You cannot query whether a specific value exists in a list. This is one of the many reasons why the Firebase documentation recommends against using arrays in the database.

But in this case (and most cases that I encounter), you may likely don't really need an array. Say that you just care about what colors your user picked. In that case, you can more efficiently store the colors as a set:

palettes
    -KSmJZ....A5I
        "0x474A39": true
        "0xbA9A7C": true
        "0xDEDEDF": true
        "0x141414": true
        "0x323E35": true

这篇关于Firebase查询随机生成的密钥中包含的十六进制代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆