javascript - 如何从 Typescript 中响应的特定属性分配表数据源?

标签 javascript angular typescript

我有一个简单的 typescript 方法来获取列表和状态,我的模型是:

export interface CashPaymentModel  {
  success: boolean;
  data: CashSpendAdHocDTO[];
}
export interface CashSpendAdHocDTO  {
  dueDate: string;
  gross: string;
  moveStageName: string;
  paidDate: string;
  service: string;
  status: string;
  timestamp: string;
  type: string;
}

我的服务方式是:

getCashPayments(policyVersionId: number, employeeId: number): Observable<CashPaymentModel> {
    return this.http.get<CashPaymentModel>(`/api/v1/policy/configuration/versions/${policyVersionId}/details?employeeId=${employeeId}`);
  }

在模板中,我想在表中显示响应列表(响应中的第二个属性),但如何分配此表数据源?

tableDataSource: Observable<CashPaymentModel>;

testMethod() {
    this.tableDataSource = this.cashPaymentService.getCashPayments(this.policyVersionId, this.employeeId).subscribe((data: CashPaymentModel) => {
      this.tableDataSource = data; .......BLA BLA BLA
    });
  }

在 ts 中,如何从响应的第二个属性正确分配 tableDataSource?

最佳答案

根据你的界面结构,你可以尝试:

testMethod() {
    this.tableDataSource = this.cashPaymentService.getCashPayments(this.policyVersionId, this.employeeId).subscribe((data: CashPaymentModel) => {
      this.tableDataSource = data.data;
    });
}

关于javascript - 如何从 Typescript 中响应的特定属性分配表数据源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58853912/

相关文章:

javascript - 定制管道产品过滤器?

angular - 根据运行时标志提供 API 或模拟版本

javascript - typescript 中的 Angular Controller

Angular 4 - 从不起作用的子组件调用父方法

javascript - 从组件文件和 View 模型生成原始 HTML 字符串

javascript - 谷歌地图 dragend 事件 v3

javascript - 在 jquery 中使用 css 对象加上宽度

javascript - ESTree 中使用什么语言来描述抽象语法树?

javascript - 如何将链接分配给类元素?

angular - 在 Nrwl/Nx 工作区中包含一些库的包