You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在KendoUI中如何修改requestEnd事件回调的event.response与event.type参数

问题解答

可以直接修改requestEnd回调入参e中的response和type属性,该事件对象是普通可写对象,没有被Kendo UI框架冻结。

现有代码问题注意

你当前贴出的代码里存在逻辑阻断问题:拿到response和type后直接执行了return 0,后续所有的toast提示、grid刷新逻辑都不会触发,需要先删掉这行无用的return语句。

示例修改方法

你可以直接在回调开头对e的属性直接赋值调整,比如适配你修改后的新接口返回结构:

requestEnd: function (e) {
    // 示例1:修改type属性,比如把create请求类型标记为update适配原有逻辑
    // e.type = 'update';

    // 示例2:修改response属性,适配新接口的返回格式,不用改动后续原有业务逻辑
    // 假设你的新接口返回结构是{code: 状态码, msg: 提示信息, data: 响应数据},就可以转成原有逻辑适配的结构
    e.response = {
        success: e.response.code === 200,
        errorMessage: e.response.msg || '操作失败',
        data: e.response.data
    };

    var response = e.response;
    var type = e.type;
    console.log(e, 'I am event');
    console.log("i triggered again and i am response", response);
    console.log("i am type", type);
    // 删掉原来的return 0,否则后面逻辑不会执行
    // return 0;
    if (type !== "read") {
        toastr.options = {
            positionClass: "toast-top-right"
        };
        if (type === 'update') {
            if (!response.success) {
                toastr.error(response.errorMessage, 'Account Update');
            } else {
                toastr.info('Acount detail successfully updated', 'Account Update');
            }
        } else if (type === 'create') {
            if (!response.success) {
                toastr.error(response.errorMessage, 'Message');
            } else {
                toastr.info('New Account successfully added', 'Message');
            }
        }

        $('#grid').data('kendoGrid').dataSource.read();
        $('#grid').data('kendoGrid').refresh();
    }
},

注意事项

对e对象属性的修改是全局生效的,不仅你后续自己的业务逻辑会用到修改后的值,Kendo UI内部后续的数据源处理逻辑也会读取修改后的属性值。如果你只需要调整自己业务逻辑用到的返回值,也可以单独定义变量处理,不用修改原e对象。


内容的提问来源于stack exchange,提问作者Joel John Centeno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 03:36:01