javascript - 数据网格不能在 Angular 中与 asp.net 核心版本 2.2 一起工作
问题描述
我在基于 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文件代码。
病人组件.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());
所以知道这里有什么问题。
谢谢
解决方案
通过在以下部分进行更改,我解决了这个问题。
this.dataSource = new CustomStore({
key: "id",
load: (loadOptions) => {
data => response.data
}
});
推荐阅读
- html - a 标签内的 img 标签不响应背景更改选项
- python - 有没有办法在 python 中使用 sns.barplot 显示不同的颜色?
- python - TypeError: __init__() 在运行 PooledOLS 时得到了一个意外的关键字参数 'entity_effects'
- nutch - nutch 作业失败失败,退出值为 255
- php - 如何识别 WooCommerce hook 'woocommerce_view_order' 使用的代码
- java - 在 AWS Amazon 上自动执行 api
- python - 如何以英寸为单位获得 matplotlib 绘图区域的大小?
- sql - 如何在PostgreSQL数据库中只保留一个条目
- c++ - c ++双向链表错误C2664'object1 :: object1(object1 &&)':无法将参数1从'int'转换为'const object1 &'
- c# - 什么是 WPF Datagrid 开头的(空)列称为