0

我有一个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,这给我带来了问题,因为我应该同时发送它们。

4

3 回答 3

2

我遇到了同样的问题。我的解决方案(解决方法?)是使用 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-01-14T17:47:59.900 回答
1

有同样的问题,要解决这个问题,您可以使用onEditorPreparing(e)事件并获取当前行的值并存储在公共变量中。

e.row.data具有当前行值。

在我的情况下,我在onSaving(e)event override中使用了存储的公共变量值e.changes

希望任何有这个问题的人都能以这种方式解决它。

于 2021-09-07T11:27:10.887 回答
0

您还可以执行以下操作:

.OnRowUpdating(@<text>function(e) { e.newData = Object.assign({}, e.oldData, e.newData);}</text>)

这将确保即使未更改的字段也会在更新时通过。

于 2021-10-28T16:05:47.157 回答