【问题标题】:Angular get item from Observable<Type<AnotherType>>Angular 从 Observable<Type<AnotherType>> 获取项目
【发布时间】:2019-05-21 06:22:22
【问题描述】:

我在 Angular 组件中添加了一些服务器端过滤。

我在页面中返回结果:Observable>

显示和过滤工作正常,但我需要另一种方法从列表中删除项目,但无法弄清楚如何从组件中访问项目。

在实施过滤之前,我在 Array 中有作业,并正在使用以下方法删除作业。虽然取消保存作业仍然有效,但如何从列表页面访问单个作业:Observable>

public unSaveJob(id: string) {
    this.jobService.unSaveJob(id);
    var jobToRemove = this.jobs.find(j => j.Id == id);
    this.savedJobs = this.jobs.filter(j => j !== jobToRemove);
}

页面

export class Page<T> {
count: number;
next: string;
previous: string;
results: Array<T>;
}

如果有人能指出正确的方向,我将不胜感激。

【问题讨论】:

  • 这取决于Page&lt;&gt; 是什么。
  • 更新了正在使用的各种组件

标签: angular typescript angular7


【解决方案1】:

发布此信息时大脑无法正常工作。因此,如果其他人已经跌倒了这个

只需在构造函数中订阅 page.results

this.page.subscribe(data => this.jobs = data.results);

并在 component.html 中显示作业而不是页面

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 2018-10-13
    • 1970-01-01
    • 2019-10-15
    相关资源
    最近更新 更多