我有一个CustomStore
如下:
this.dataSource = new CustomStore({
key: "id",
load: ()=>this.sendRequest("GET"),
insert: (values) => this.sendRequest("POST",JSON.stringify(values)),
update: (key, values) => this.sendRequest("PUT", {
id: key,
values: values
}),
});
并且低实现SendRequest
是这样的:
sendRequest(method: string = "GET", data: any = {}): any {
let result;
switch(method) {
case "GET":
result = this.mService.get();
break;
case "POST":
result = this.mService.create(data);
break;
case "PUT":
debugger;
let manu: IManu = { id: data.id, name: data.values.name,description:data.values.description };
result = this.mService.update(manufacture);
break;
}
return result
.toPromise()
.then((data: any) => {
return method === "GET" ? {data:data.items,totalCount: data.items.length} : data;
})
.catch(e => {
throw e && e.error && e.error.Message;
});
}
和 html 模板是:
<div class="content-block">
<dx-data-grid class="dx-card wide-card" [dataSource]="dataSource" [remoteOperations]="true" [showBorders]="false" [focusedRowEnabled]="true"
[focusedRowIndex]="0" [columnAutoWidth]="true" [columnHidingEnabled]="true"
(onSaving)="logEvent('Saving')">
<dxo-paging [pageSize]="10"></dxo-paging>
<dxo-pager [showPageSizeSelector]="true" [showInfo]="true"></dxo-pager>
<dxo-filter-row [visible]="true"></dxo-filter-row>
<dxo-selection mode="multiple" [deferred]="true"></dxo-selection>
<dxo-editing mode="popup" [allowUpdating]="true" [allowDeleting]="true" [allowAdding]="true" >
<dxo-popup title="Manu" [showTitle]="true" [width]="600" [height]="450">
</dxo-popup>
<dxo-form>
<dxi-item itemType="group" [colCount]="2" [colSpan]="2">
<dxi-item dataField="name" [colSpan]="2"></dxi-item>
<dxi-item dataField="description" [colSpan]="2" editorType="dxTextArea" ></dxi-item>
</dxi-item>
</dxo-form>
</dxo-editing>
<dxi-column dataField="name" [width]="250" caption="Name" [hidingPriority]="2" >
<dxi-validation-rule type="required"></dxi-validation-rule>
</dxi-column>
<dxi-column dataField="description" caption="Description" [hidingPriority]="1" >
</dxi-column>
</dx-data-grid>
</div>
问题是,当我想编辑一行时,在弹出窗口中我改变了 justDescription
和 insendRequest
方法,我只是进入description
并且values
没有name
,这给我带来了问题,因为我应该同时发送它们。