e.preventDefault()阻止了剑道“阅读”。事件,但不适用于'创建'在kendo弹出编辑器中更新按键

时间:2014-12-02 09:45:54

标签: kendo-ui kendo-grid

 transport: {
            parameterMap: function (data, operation) {
                if (operation !== "read") {
                    return JSON.stringify(data);
                } else {
                    return (data);
                }
            },
            read: {
                url: function () {
                    return moduleServiceRoot;
                },
                type: "GET",
                dataType: "json",
                async: true
            },
            create: {
                url: function (rec) {
                    return moduleServiceRoot; 
                },
                type: "POST",
                contentType: 'application/json; charset=utf-8',
                dataType: "json",
                async: true
            },
            complete: function (e) {
                $("#grid").data("kendoGrid").dataSource.read();
                async: true
            },
        },
        requestStart: function (e) {
            console.log('request started');
            if (e.type == 'create' & validInput == false) {
                console.log('request started');
                e.preventDefault();
            }
        }

在上面的代码中,validInput始终为false。如果我注释掉if语句kendo网格读取操作被阻止(网格没有显示任何数据),但如果我取消注释它,当我在kendo弹出编辑器中点击更新时,它就不能用于kendo创建。

1 个答案:

答案 0 :(得分:1)

create: function (options) {
                if (validInput) {
                    $.ajax({
                        url: moduleServiceRoot,
                        dataType: "json",
                        type: "POST",
                        contentType: 'application/json; charset=utf-8',
                        async: true,
                        data: JSON.stringify(options.data),
                        success: function (result) {            // notify the data source that the request succeeded,
                            options.success(result);
                        },
                        error: function (result) {              // notify the data source that the request failed
                            options.error(result);
                        }
                    });
                }
            }

并且工作正常