【发布时间】:2023-05-07 11:03:01
【问题描述】:
我有一个 JSON 数据,我使用 *ngFor 将“accountNumber”显示到下拉列表中。由于 JSON 数据中有多个条目具有相同的帐号,因此我在下拉列表中多次看到相同的帐号。 enter image description here
html:
Select
json:
`[
{
"accountNumber": 7890,
"transactionDate": "4/2/2016",
"postingDate": "4/3/2016",
"description": "Pok Pok Thai",
"category": "Restaurants",
"amount": 15.00
},
{
"accountNumber": 7890,
"transactionDate": "4/3/2016",
"postingDate": "4/4/2016",
"description": "Pok Pok Hai",
"category": "Hotel",
"amount": 25.00
},
{
"accountNumber": 8901,
"transactionDate": "4/6/2016",
"postingDate": "4/7/2016",
"description": "Pok Pok Fai",
"category": "Dairy",
"amount": 55.00
},
{
"accountNumber": 8901,
"transactionDate": "4/7/2016",
"postingDate": "4/8/2016",
"description": "Pok Pok Aai",
"category": "Automotive",
"amount": 65.00
},
{
"accountNumber": 4567,
"transactionDate": "4/9/2016",
"postingDate": "4/10/2016",
"description": "Pok Pok Cai",
"category": "Healthcare",
"amount": 85.00
},
{
"accountNumber": 4567,
"transactionDate": "4/10/2016",
"postingDate": "4/11/2016",
"description": "Pok Pok Dai",
"category": "Healthcare",
"amount": 95.00
},
{
"accountNumber": 8901,
"transactionDate": "4/12/2016",
"postingDate": "4/13/2016",
"description": "sit amet",
"category": "Software",
"amount": 115.00
}
]`
如何避免在下拉列表中显示重复的帐号值?我假设它需要一个自定义管道,但不知道该怎么做。
我是 Angular 2 的新手,并尝试寻找解决方案,但找不到适合我需要的任何东西。
-
那你搜索的不够仔细:) stackoverflow.com/questions/34417250/…
-
您可以将帐号加载到一个集合中,然后在上面迭代您的 ngFor。