如果这些数据需要每个数据的价格,我应该使用什么数据结构?

发布于 2025-01-11 14:00:54 字数 283 浏览 0 评论 0原文

我有这个产品数据,一旦为特定产品下了订单,我还需要减去颜色的数量。

现在,这是我的数据结构,其中 colorMap 是一个 Map。

输入图片此处描述

问题:如果我需要每种颜色有不同的价格怎么办?我应该将 colorMap 更改为数组吗?

I have this product data where I would also need to subtract the quantity of the colors once an order was placed for the specific product.

For now, this is my data structure where the colorMap is a Map.

enter image description here

Problem: What if I need to have different prices for each of the colors? Should I change the colorMap into an array?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2025-01-18 14:00:54

据我了解,颜色的价格丢失了。假设每种颜色的价格不同,解决此问题的最合适方法是在文档中创建一个名为 colors 的 Color 对象数组,如下所示:

$docId
  |
  --- cat: "ML"
  |
  --- colors (array)
  |    |
  |    --- 0
  |    |   |
  |    |   --- colorName: "Black"
  |    |   |
  |    |   --- quantity: 20
  |    |   |
  |    |   --- price: 11.99
  |    |
  |    --- 1
  |        |
  |        --- colorName: "Green"
  |        |
  |        --- quantity: 5
  |        |
  |        --- price: 14.99
  |
  --- price: 200 //Remove that if not necessary
  |
  --- prodName: "Thumbler"
  |
  --- size: "500"

通过这种方式,您可以简单地读取数组并计算总数。

由于您没有设置标签,因此我们不知道您正在构建适用于 Android、iOS 还是 Web 的应用程序。如果碰巧它适用于 Android,这里有一篇有用的文章:

As far as I understand, the price of the color is missing. Assuming that you have a different price for each color, the most appropriate way to solve this would be to create inside the document, an array of Color objects called colors like this:

$docId
  |
  --- cat: "ML"
  |
  --- colors (array)
  |    |
  |    --- 0
  |    |   |
  |    |   --- colorName: "Black"
  |    |   |
  |    |   --- quantity: 20
  |    |   |
  |    |   --- price: 11.99
  |    |
  |    --- 1
  |        |
  |        --- colorName: "Green"
  |        |
  |        --- quantity: 5
  |        |
  |        --- price: 14.99
  |
  --- price: 200 //Remove that if not necessary
  |
  --- prodName: "Thumbler"
  |
  --- size: "500"

In this way, you can simply read the array and calculate the total.

Since you didn't set a tag, we don't know if you are building an app that is for Android, iOS, or web. If by chance it's for Android, here is a useful article:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文