【问题标题】:Show atributte of an specific object searching by id with angular显示特定对象的属性,通过 id 和角度搜索
【发布时间】:2019-09-14 18:46:20
【问题描述】:

我最近在 angular... 我有一个数据列表,这些数据在表格的视图中显示。我需要在其中一列中显示数组“availableProducts”中每个对象的“描述”属性

数据示例:

availableProducts = [
    {"sending":true,"id":"8c94a40561b6d76243bea11f","cod":"123ABC","description":"Description 1","dateUpd":"2019-03-22T08:59:17.996Z","__v":0},
    {"sending":false,"id":"8ca378ee413da0715b5b48d6","cod":"987ZYX","description":"Description 2","dateUpd":"2019-04-25T08:23:11.286Z","__v":0},
    {"sending":false,"id":"8bc07055cb116b1698d4b1be","cod":"000AAA","description":"Description 3","dateUpd":"2019-04-24T14:18:29.378Z","__v":0},
    {"sending":false,"id":"8ac16e5564169a5233db4456","cod":"111BBB","description":"Description 4","dateUpd":"2019-04-25T08:22:23.456Z","__v":0}
]

我需要搜索 id,因为该值在每行数据中都不同,在我的表中,该值对应于显示产品对象 id 的“invoice.product”。 为了理解这一点,我给你一个猫鼬模型“发票”的例子:

{
  "id" : ObjectId("5cb5811ffb5c03579281e22f"),
  "name": "string",
  "number": "671782",
  "contractId": "C8282",
  "product": {
    "id": ObjectId("8c94a40561b6d76243bea11f"),
    "sending": true,
    "cod":"123ABC",
    "description":"Description 1",
    "dateUpd":"2019-03-22T08:59:17.996Z"
  },
  "url": "string",
  "__v" : 0
}

到目前为止我要展示的是这个,但它显示了所有的描述,我希望你通过 id 查找具体的描述,我该怎么做?

<td class="text-center">
     <div class="badge" ng-repeat="prod in availableProducts | filter: invoice.product">{{ prod.description }}</div>
</td>

【问题讨论】:

  • 你得到的invoice.product 正确吗?
  • 是的,invoice.product的值就是id的值(例如:“8c94a40561b6d76243bea11f”)
  • 所以你想在产品 id 匹配 invoice.product 时显示描述,对吗?试试下面的答案,看看是否有帮助。

标签: node.js angular mongoose


【解决方案1】:

我不熟悉猫鼬。但我认为这可能会解决您的问题,

<td class="text-center">
     <div class="badge" *ngFor="let prod of availableProducts" [hidden]="prod.id!=invoice.product">
         {{ prod.description }}
     </div>
</td>

【讨论】:

  • 完美运行!!解决了我的问题,谢谢!! :)
猜你喜欢
  • 2021-05-26
  • 2019-08-08
  • 1970-01-01
  • 1970-01-01
  • 2017-02-27
  • 2015-05-01
  • 2018-01-16
  • 1970-01-01
  • 2019-03-10
相关资源
最近更新 更多