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

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

问题描述

这是我的 firebase 数据结构:

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

在 Android 中,我只有一个代码可以从子成分"中检索所有值

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

推荐答案

那是因为您已将成分存储在数组中.Firebase 将数组视为一个对象;不能添加、更改或删除元素.数组的唯一选择是重写整个数组以保持顺序索引.

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 to maintain a sequential index.

最重要的是,在 Firebase 中通常应该避免使用数组.请参阅有关它们的此 Firebase 博客数组是邪恶的.另外,如果您想了解更多信息,请在此处搜索Arrays Are Evil"

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"

像 -Yhiipkpokosd 这样的每个键,都是用 childByAutoId 或 push() 生成的.

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

这种结构非常灵活,因为它可以扩展...

This structure is amazingly 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天全站免登陆