有没有一种更干净的方法来用Java中的Map填充对象列表?

时间:2020-07-17 18:36:15

标签: javascript arrays object model mapping

我有一个包含要添加到对象列表中的对象数组的响应。有没有一种更干净的方法可以做到这一点?

列表的人口: 这是我订阅端点并形成模型的地方。

然后我遍历响应列表,制定模型,然后推送到我的列表。

private _customViews: CustomViewModel[]
  get customViews() {
    return this._customViews;
  }

  constructor(
    private _configService: ConfigService,
    private _http: HttpClientQ) {
      super();
      this._customViews = [];
      this.getCustomViews().subscribe( view => {
        view.map(customView => {
          this._customViews.push({
            Id: customView.id,
            name: customView.name,
            UserId: customView.userId,
            TableId: customView.tableId,
            columns: customView.userViewColumns.map(column => ({
              SourceColumnId: column.sourceColumnId,
              headerText: column.sourceColumns.name,
              toolTip: column.sourceColumns.name,
              fieldName: column.sourceColumns.name,
              SortOrder: column.sortOrder,
              TableId: customView.tableId,
              ViewId: customView.id
            }))
          })
        })
      });
    }

模型::这些是制定新对象时使用的模型。

export class CustomViewModel {
    Id?: number;
    name: string;
    UserId?: string;
    TableId: number;
    columns: CustomViewColumnModel[];
    UserViewColumns?: CustomViewColumnModel[];
}

export class CustomViewColumnModel {
    SourceColumnId: number;
    headerText: string;
    toolTip: string;
    fieldName: string;
    SortOrder: number;
    TableId?: number;
    ViewId?: number;
}

0 个答案:

没有答案