我有一个如下所示的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>问题是,当我想编辑一行时,在弹出窗口中我只更改了Description,在sendRequest方法中,我只是在values中获得了description,而没有name,这对我来说是一个问题,因为我应该同时发送这两个文件。
发布于 2021-01-15 01:48:00
我也遇到过同样的问题。我的解决方案(解决办法?)是使用PATCH而不是PUT。
下面是更新处理程序:
update: (key, values) => {
let patch = "[";
var props = Object.getOwnPropertyNames(values);
props.forEach(x => {
var property = `{ op: 'replace', path: '/${x}', value: '${values[x]}' }`;
patch += property;
});
patch += "]";
return fetch(`orders/${encodeURIComponent(key)}`, {
method: "PATCH",
body: patch,
headers: {
'Content-Type': 'application/json-patch+json'
}}).then(handleErrors);
},那么身体就是
[
{
"op":"replace",
"path":"/description",
"value": "new value"
}
]发布于 2021-09-07 11:27:11
也有同样的问题,为了解决这个问题,您可以使用onEditorPreparing(e)事件,获取当前行的值并存储在公共变量中。
e.row.data具有当前行值。
在我的例子中,我在onSaving(e)事件覆盖e.changes中使用了存储的公共变量值。
希望每个人都能用这种方式解决这个问题。
发布于 2021-10-28 16:05:47
您还可以执行以下操作:
.OnRowUpdating(@<text>function(e) { e.newData = Object.assign({}, e.oldData, e.newData);}</text>)这将确保即使没有更改的字段也会在更新时传递。
https://stackoverflow.com/questions/64881195
复制相似问题