如何在Angular Grid中显示JSON嵌套数据

问题描述 投票:0回答:1

我正在研究Angular 5应用程序,我得到了具有以下数据结构的类,我需要在模板中显示,可能使用Angular Kendo UI Grid,如果没有那么样本以格式显示

我在json中获得了以下类数据

export class MyClass{
ConsultationId: string;
ResponseType: {
    id: string;
    Name:string;
};
TotalResponses: string;
TotalNewResponses:string;
TotalReviewResponses:string;
TotalCompletedResponses:string;
responsesAbstract: {
    ResponseId: string;
    ConsultationId: string;
    ResponseTypeId:string;
    RespondentId:string;
    ResponseCurrentStatus:string
}

}

屏幕截图的json数据

enter image description here

尝试按{{MyClass.ResponseType.Name}}打印ResponseType名称,但Angular无法识别它

angular kendo-ui-grid
1个回答
1
投票

我认为你必须根据你的数据更新类属性

export class MyClass {
  consultationId: string;
  responseType: {
    id: string;
    name: string;
  };
  totalResponses: string;
  totalNewResponses: string;
  totalReviewResponses: string;
  totalCompletedResponses: string;
  responsesAbstract: {
    responseId: string;
    consultationId: string;
    responseTypeId: string;
    respondentId: string;
    responseCurrentStatus: string;
  };
}

在组件中

class Component {
  items: MyClass[] = [];

  assign(data) {
    this.items = data;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.