我有一个简单的 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/