为什么我在具有嵌套 2 个级别的 firebase 实时基础中为第一级的键获得 None [英] Why do I get None for key for first level in firebase realtime base with nested 2 levels

查看:38
本文介绍了为什么我在具有嵌套 2 个级别的 firebase 实时基础中为第一级的键获得 None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遍历孩子,但我得到 None 作为第一个键,例如应该是案件编号.

.

I am trying to iter through childs, but I get None for first key which should be e.g. id of case.

example of code

and this is result of code [None, {'-MaISrSqXnill-8W7sG1': {'datum': '22.5.2021', 'idtip_uplate': '11', 'iduplata': '1', 'novaca': '50', 'predmet': '1'}}]

For some reason he don't see first key

解决方案

When you use numeric keys (like the 1) in your data, you run the risk that Firebase will try to be helpful and interpret those keys as indexes in an array. So in your data it sees it as an array of size 2, with no element at index 0 and the -M... element at index 1. And that's what the output you print shows.

To prevent Firebase from interpreting the keys as an array, ensure they start with a string value. So prefix them with a short known value, like "key1".

For more on this, also see: Best Practices: Arrays in Firebase.

这篇关于为什么我在具有嵌套 2 个级别的 firebase 实时基础中为第一级的键获得 None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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