为什么KendoUI Grid在调用options.error函数时不会回滚删除?

use*_*254 8 datasource kendo-ui kendo-grid

我在这里放了一个小提琴来证明这个问题.

http://jsfiddle.net/codeowl/fmzay/1/

只需删除一条记录,它应该回滚删除,因为我从destroy函数内部调用options.error.

为什么网格不会回滚?

问候,

斯科特

标记:

<div id="KendoGrid"></div>
Run Code Online (Sandbox Code Playgroud)

JS:

var _data = [
        { Users_ID: 1, Users_FullName: 'Bob Smith', Users_Role: 'Administrator'  },
        { Users_ID: 2, Users_FullName: 'Barry Baker', Users_Role: 'Viewer'  },
        { Users_ID: 3, Users_FullName: 'Bill Cow', Users_Role: 'Editor'  },
        { Users_ID: 4, Users_FullName: 'Boris Brick', Users_Role: 'Administrator'  }
    ],
    _dataSource = new kendo.data.DataSource({ 
        data: _data,
        destroy: function (options) {
            options.error(new Error('Error Deleting User'));
        }
    });

$('#KendoGrid').kendoGrid({
    dataSource: _dataSource,
    columns: [
        { field: "Users_FullName", title: "Full Name" },
        { field: "Users_Role", title: "Role", width: "130px" },
        { command: ["edit", "destroy"], title: "&nbsp;", width: "180px" }
    ],
    toolbar: ['create'],
    editable: 'popup'
});
Run Code Online (Sandbox Code Playgroud)

Ona*_*Bai 17

发信号错误是不够的.让我们说删除记录时出错是不够的,因为KendoUI不知道记录是否已在服务器中被删除,而且回复是产生错误的记录.所以KendoUI方法是一种保守的方法:你必须决定做什么并明确地说出来:

所以你应该做的是添加error一个cancelChanges在网格中调用a 的hander函数.

代码是:

_dataSource = new kendo.data.DataSource({
    transport: {
        read: function(options) {
            options.success(_data);
            console.log('Read Event Has Been Raised');
        },
        destroy: function (options) {
            options.error(new Error('Error Deleting User'));
            console.log('Destroy Event Has Been Raised');
        }
    },
    schema: {
        model: {
            id: "Users_ID",
            fields: {
                Users_ID: { editable: false, nullable: true },
                Users_FullName: { type: "string", validation: { required: true } },
                Users_Role: { type: "string", validation: { required: true } }
            }
        }
    },
    error: function(a) {
        $('#KendoGrid').data("kendoGrid").cancelChanges();
    }
});
Run Code Online (Sandbox Code Playgroud)

更新的JSFiddle在这里:http://jsfiddle.net/OnaBai/fmzay/3