1

我尝试将一个角度模板移动到另一个角度模板。移动后,我运行 nswag 文件,然后运行应用程序。数据未映射,因为返回结果包含结果关键字,但 nswag 生成的文件未考虑结果关键字。我修改了 nswag 生成的 service-proxy _data.result 然后只定义了它的工作 C# 文件返回结果

{
  "pastRecords": [
    {
      "date": "2020-01-30T04:47:05.350Z",
      "value": {}
    }
  ],
  "futureRecords": [
    {
      "date": "2020-01-30T04:47:05.350Z",
      "value": {}
    }
  ]
}

但它回来了

{
  "result": {
    "pastRecords": [
      {
     "date": "2020-01-30T04:47:05.350Z",
      "value": {}
      }
  ],
  "futureRecords": [
    {
      "date": "2020-01-30T04:47:05.350Z",
      "value": {}
    }
  ]
}

以前的模板只定义了 _data 但它可以工作,但新模板需要 _data.result

init(_data?: any) {
    if (_data) {
        if (Array.isArray(_data["pastRecords"])) {
            this.pastRecords = [] as any;
            for (let item of _data["pastRecords"])
                this.pastRecords.push(ChartSingleResultDto.fromJS(item));
        }
        if (Array.isArray(_data["futureRecords"])) {
            this.futureRecords = [] as any;
            for (let item of _data["futureRecords"])
                this.futureRecords.push(ChartSingleResultDto.fromJS(item));
        }
    }
}

这个适用于以前的模板,但需要新模板

init(_data?: any) {
    if (_data) {
        if (Array.isArray(_data.result["pastRecords"])) {
            this.pastRecords = [] as any;
            for (let item of _data.result["pastRecords"])
                this.pastRecords.push(ChartSingleResultDto.fromJS(item));
        }
        if (Array.isArray(_data.result["futureRecords"])) {
            this.futureRecords = [] as any;
            for (let item of _data.result["futureRecords"])
                this.futureRecords.push(ChartSingleResultDto.fromJS(item));
        }
    }
}
4

0 回答 0