【问题标题】:datagrid not working in angular with asp.net core version 2.2数据网格不能在 Angular 中与 asp.net 核心版本 2.2 一起工作
【发布时间】:2021-04-01 03:46:23
【问题描述】:

我在基于 asp.net 核心和角度的项目中使用 Devextreme 的 Datagrid 小部件。

JSON 响应如下。

{
    "result": {
        "items": [
            {
                "firstName": "Asu",
                "lastName": "Voh",
                "emailId": "Asu@g.com",
                "dateOfBirth": "2020-12-12T00:00:00",
                "isdiabetes": "No",
                "gender": "Female",
                "isadmittedbefore": false,
                "isDeleted": false,
                "deleterUserId": null,
                "deletionTime": null,
                "lastModificationTime": null,
                "lastModifierUserId": null,
                "creationTime": "2020-12-12T00:00:00",
                "creatorUserId": null,
                "id": 4
            }
        ]
    },
    "targetUrl": null,
    "success": true,
    "error": null,
    "unAuthorizedRequest": false,
    "__abp": true
}

下面是我使用的角度代码,下面是html文件代码。

患者.component.html:

<div [class]="containerClass">
            <div class="card card-custom">
                <div class="card-body">
                    <dx-data-grid
                        id="patientgrid"
                        [dataSource]="dataSource"
                        [repaintChangesOnly]="true"
                        [showBorders]="true">

                        <dxo-scrolling mode="virtual"></dxo-scrolling>

                        <dxi-column dataField="firstName" caption="{{'FirstName' | localize}}"></dxi-column>
                        <dxi-column dataField="lastName" caption="{{'LastName' | localize}}"></dxi-column>
                        <dxi-column dataField="emailId" caption="{{'EmailId' | localize}}"></dxi-column>
                        <dxi-column dataField="dateOfBirth" caption="{{'DateOfBirth' | localize}}"></dxi-column>
                        <dxi-column dataField="isdiabetes" caption="{{'Isdiabetes' | localize}}"></dxi-column>
                        <dxi-column dataField="gender" caption="{{'Gender' | localize}}"></dxi-column>
                        <dxi-column dataField="isadmittedbefore" caption="{{'Isadmittedbefore' | localize}}"></dxi-column>
                    </dx-data-grid>
                </div>
            </div>
        </div>

下面是ts文件代码

患者.component.ts

export class PatientsComponent extends AppComponentBase {

    dataSource: any = {};
    refreshMode : string;

  constructor(
      injector : Injector,
      private _patientService: PatientServiceProxy
    ) {
      super(injector);
      this.getData();
  }

  getData(){
      this.refreshMode = "full";

      /*this._patientService.getPatient("").subscribe(
          result => {
              console.log(result);
          });*/

      //http://localhost:22742/api/services/app/Patient/GetPatient

        this.dataSource = new CustomStore({
            key: "id",
            load: (loadOptions) => {
                return this._patientService.getPatient("").toPromise()
               }
           });
  }

  ngOnInit() {
  }

我搜索了这个错误并找到了更新startup.cs文件的解决方案,所以我喜欢下面..但仍然会出现错误。

我还更新了我的启动文件,如下所示。

services.AddMvc()
                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

所以知道这里出了什么问题。

谢谢

【问题讨论】:

  • 什么是CustomStore?顺便提一句。这似乎与 ASP.NET Core 后端无关,因为正如您所说,服务器正在正确返回数据。
  • @poke 这是基于 aspnetzero 框架和 customstore 是 devextreme 创建数据网格小部件的选项。
  • 您的 JSON 响应似乎与 according to the docs 所需的格式不匹配。例如,这些项目应位于 data 属性中。
  • 是的..你是对的..现在完成了..感谢您的指导..

标签: javascript angular asp.net-core devextreme devextreme-angular


【解决方案1】:

通过在以下部分进行更改,我解决了这个问题。

this.dataSource = new CustomStore({
            key: "id",
            load: (loadOptions) => {
                data => response.data
               }
           });

【讨论】:

    猜你喜欢
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多