首页 > 解决方案 > 使用 vanilla JS 模拟购物车功能

问题描述

我正在用 express 构建一个商店经理应用程序,它要求我拥有三个模型,用户、产品和销售。我想为销售模型实现购物车功能,所以我有这样的东西:

const carts = [
   // Cart 1
   {
    {
    Product: Product1 
    Quantity: 20 
    Unit Price: 500 
    Amount: 10000
   },
   {
    Product: product2 
    Quantity: 5 
    Unit Price: 15000 
    Amount: 75000
   },
    {
    Product: anotherProduct 
    Quantity: 10 
    Unit Price: 500 
    Amount: 5000
    },
    {
    Product: Product3 
    Quantity: 2 
    Unit Price: 500 
    Amount: 1000
   },
   Total : 91000
  },

  // Cart 2
  {
   {
    Product: product1 
    Quantity: 20 
    Unit Price: 500 
    Amount: 10000
   },
   {
    Product: product2 
    Quantity: 5 
    Unit Price: 15000 
    Amount: 75000
   },
   Total: 80000
  }
 ];

Cart 1 代表一个服务员的销售,而 Cart 2 代表另一个服务员的销售。如何包含 saleId、attachantId 和 total 以便于参考?注意我将要通过销售模型运行搜索/循环以按 saleId 过滤

标签: javascriptarraysobject

解决方案


推荐阅读