Firebase更改android中的子数据信息的布局 [英] Firebase Changing layout of child data information in android

查看:102
本文介绍了Firebase更改android中的子数据信息的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的firebase数据结构:



在我的应用程序中打印出来的结果如下:



我如何改变这个?所以它不显示逗号?但换成新的行



在Android中,我只是有一个代码,检索所有的孩子成分的价值

这是因为你已经将你的成分存储在一个数组中。 Firebase将数组视为一个对象;元素不能添加,更改或删除。数组的唯一选择是重写整个数组。



底线是在Firebase中通常应避免使用数组。有关这些Firebase博客的信息,请参阅阵列是邪恶。另外,如果你想获得更多的信息,可以在这里搜索阵列是邪恶的。

还有很多其他的方法来存储你的数据,这些数据更加灵活。例如

  -Yuyijiomapsd 
dish_name:杰仔意粉酱
配料
-Yhiipkpokosd
名称:大蒜
-Yu8jj99s9jis
名称:罗勒
-Yijijjis99ss
名称:红酒

每个键如-Yhiipkpokosd都是用childByAutoId或push()生成的。

结构是灵活的,因为它可以扩大...

  -Yuyijiomapsd 
dish_name:Jay's意粉酱
原料
-Yhiipkpokosd
名称:大蒜
数量:两个丁香,切碎
-Yu8jj99s9jis
名称:罗勒
数量:1/2杯
-Yijijjis99ss
名称:红酒
数量:尽可能多

您也可以使用Deep Query来查询它,例如,您可以查询整个数据库,查看所有红葡萄酒的食谱m。

This is my firebase data structure:

And when printing out this in my app, it goes like:

How do I change this? so it doesn't display it with commas? but instead new lines

In Android, I just had a code that retrieves all the values from child "ingredients"

解决方案

That's because you've stored your ingredients in an array. Firebase treats arrays as one object; elements cannot be added, changed or removed. The only option with arrays is to re-write the entire array.

The bottom line is that arrays should generally be avoided in Firebase. See this Firebase blog about them Arrays Are Evil. Also, if you want a lot more information, search here for 'Arrays Are Evil'

There are a number of other ways to store your data which are much more flexible. For example

-Yuyijiomapsd
   dish_name: "Jay's Spaghetti Sauce"
   ingredients
     -Yhiipkpokosd
        name: "Garlic"
     -Yu8jj99s9jis
        name: "Basil"
     -Yijijjis99ss
        name: "Red Wine"

Each key like -Yhiipkpokosd, is generated with childByAutoId or push().

This structure is amnazingly flexible as it can be expanded...

-Yuyijiomapsd
   dish_name: "Jay's Spaghetti Sauce"
   ingredients
     -Yhiipkpokosd
        name: "Garlic"
        qty: "Two cloves, minced"
     -Yu8jj99s9jis
        name: "Basil"
        qty: "1/2 cup"
     -Yijijjis99ss
        name: "Red Wine"
        qty: "As much as you like"

You can also query it with a Deep Query, so for example, you could query the entire database for all recipes that have Red Wine in them.

这篇关于Firebase更改android中的子数据信息的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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