【问题标题】:How can i subtract Array value that inside the object? [closed]如何减去对象内部的数组值? [关闭]
【发布时间】:2018-08-24 06:37:54
【问题描述】:

对象的 JSON

{
    "ProductId": 20,
    "ProductName": "LCD",
    "ProductDescription": "Sony",
    "BuyingPrice": "15000 ",
    "VendorId": 46,
    "CategoryId": 25,
    "CreatedBy": 0,
    "UpdateBy": null,
    "IsActive": true,
    "IsDeleted": false,
    "CreatedDate": "2018-03-14",
    "UpdatedDate": null,
    "WareHouseProducts": [
        {
            "WareHouseProductsId": 11,
            "TotalQuantity": 15,
            "AvailableQuantity": 8,
            "ProductId": 20,
            "WareHouseId": 4,
            "CreatedBy": null,
            "UpdateBy": null,
            "IsActive": true,
            "IsDeleted": false,
            "CreatedDate": "2018-03-14",
            "UpdatedDate": "2018-03-15",
            "WarehouseName": "Warehouse 1"
        }

    ]
}

我想减去 AvailableQuantity 或更改事件..

 this.products.find(p => p.ProductId == this.selectedProduct)
    .WareHouseProducts.find(w => w.AvailableQuantity == this.selectedProduct)
    .AvailableQuantity - this.quantity;

我试过了,但没用

我需要减去仓库产品可用数量请帮帮我..

【问题讨论】:

  • this.selectedProduct 是什么我想你必须选择其中的值来匹配
  • this.selectedProduct 是下拉列表.. this.quantity 是输入数字... 用户可以在单击添加按钮时选择产品添加数量,例如 5 或 6... 我想减去可用数量跨度>
  • 请发布一个例子!
  • 请发布您的下拉列表以及您如何获得用户选择的价值

标签: javascript arrays angularjs typescript


【解决方案1】:

您的代码应该可以工作,可能是第二次发现有错误,它应该是 ProductId 而不是 AvailableQuantity .find(w => w.ProductId === this.selectedProduct)

【讨论】:

  • 没有任何可验证的例子,很难理解这个问题。然而,这可能是潜在的问题。赞成!
  • 感谢您的帮助。但实际上这也没有帮助我:(..这是我发布w.AvailableQuantity的错误实际上是productId。每个人都感谢我自己解决这个问题的帮助..这是我问题的解决方案:-@987654322 @
猜你喜欢
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-15
  • 1970-01-01
相关资源
最近更新 更多