【问题标题】:Filter Json Array Data in Typescript在 Typescript 中过滤 Json 数组数据
【发布时间】:2021-05-29 01:19:29
【问题描述】:

我最近开始研究 angular,我需要从 JSON 数组中过滤数据。 基本上我想显示 id 小于 100 的名称。下面对我不起作用。

list : any;

getOptionList(){
this.callingService.getData().pipe(
  filter((l) => l.id < 100)
).subscribe(
  (l) => { this.list = l;} 
)
}
}

调用Service的Json数组

[
  {
    "id":1,
    "name": "A"
  },
  {
    "id":2,
    "name": "B"
  },
  ...
]

【问题讨论】:

    标签: json angular typescript filter observable


    【解决方案1】:
    this.callingService.getData().subscribe((res: any) => {
          let filteredArr = res.filter(data => data.id < 100);
          //Here you got the filtered array.
    });
    

    它会为你工作。

    【讨论】:

    • 如果此代码有效,请标记为正确我的答案。
    • 非常感谢您尝试了另一种方法。有效!
    猜你喜欢
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    相关资源
    最近更新 更多