从未调用过的Kendo UI数据源OData传输提交函数

时间:2016-10-06 08:39:50

标签: kendo-ui grid datasource transport

我用数据源创建了一个kendo UI网格。我想实现批处理模式。我发现了这篇文章batch editing odata。我添加了我的代码sumbit函数但从不调用。

同样来自Kendo文档transport submit

问题是这个sumbit函数从不调用!!

更新并创建被调用,并且在Telerik配置中说:“通常,您将transport.read和transport.submit操作一起定义.transport.create,transport.update和transport.delete操作将不会在这种情况。“

我有很多代码无需查看..问题是grid is batch == true,并且submit函数从不调用。

$scope.grid.dataSource = {
serverSorting: true,
type: "odata",
batch: $scope.config.grid.dataSource.batch,
transport: {
    read: {
        url: $scope.config.grid.dataSource.readUrl,
        complete: function (e) {
            $scope.notification.hide();
            if (e.statusText != 'error') {
                $scope.handler.enabledButtons();
            }
            else {
                $scope.$apply(function () {
                    $scope.notification.show('Something went wrong while loading data. Please try later.' + ' Error code: ' + e.status, "error");
                });
                $scope.handler.disableButtons();
                $("#grid" + $scope.config.id).data("kendoGrid").refresh();
            }
        }
    },
    submit: function (e) {
        console.log(e);
    },
        create: {
            url: function (data) {
                return $scope.config.grid.dataSource.crudUrl;
            },
            type: "POST",
            complete: function (e) {
                $scope.notification.hide();
                if (e.status == '201')
                    $scope.notification.show('Item created successfully.', "info");
                else {
                    try {
                        $scope.notification.show('Create failed. ' + (JSON.parse(e.responseText))["odata.error"].message.value, 'error');
                    }
                    catch (exception) {
                        $scope.notification.show('Create failed. An error occurred.' + ' ( Error code: ' + e.status + ' )', 'error');
                    }
                    $scope.handler.createFailed();
                }
            }
        },
        update: {
            url: function (data) {
                console.log(data)
                if ($scope.config.grid.model.guid)
                    return $scope.config.grid.dataSource.crudUrl + "(guid'" + data[$scope.config.grid.model.id] + "')";
                return $scope.config.grid.dataSource.crudUrl + "('" + data[$scope.config.grid.model.id] + "')";
            },
            type: "PUT",
            beforeSend: function (xhr) {
                if ($scope.config.grid.dataSource.transport.beforeSend)
                    xhr.setRequestHeader('If-Match', '*');
            },
            complete: function (e) {
                $scope.notification.hide();
                if (e.status == '204') {
                    $scope.notification.show('Item Saved successfully.', "info");
                }
                else {
                    try{
                        $scope.notification.show('Update failed. ' + (JSON.parse(e.responseText))["odata.error"].message.value, 'error');
                    }
                    catch (exception) {
                        $scope.notification.show('Update failed. An error occurred.' + ' ( Error code: ' + e.status + ' )', 'error');
                    }
                    $scope.handler.updateFailed();
                }
            }
        },
        destroy: {
            url: function (data) {
                if ($scope.config.grid.model.guid)
                    return $scope.config.grid.dataSource.crudUrl + "(guid'" +  data[$scope.config.grid.model.id]+ "')";
                return $scope.config.grid.dataSource.crudUrl + "('" + data[$scope.config.grid.model.id] + "')";
            },
            type: "DELETE",
            beforeSend: function (xhr) {
                if ($scope.config.grid.dataSource.transport.beforeSend)
                    xhr.setRequestHeader('If-Match', '*')
            },
            complete: function (e) {
                $scope.notification.hide();
                if (e.status == '204')
                    $scope.notification.show('Deleted successfully.', "info");
                else {
                    try {
                        $scope.notification.show('Delete failed. ' + (JSON.parse(e.responseText))["odata.error"].message.value, 'error');
                    }
                    catch (exception) {
                        $scope.notification.show('Delete failed. An error occurred.' + ' ( Error code: ' + e.status + ' )', 'error');
                    }
                    $scope.handler.destroyFailed();         
                }
            }
        },
    parameterMap: function (options, type) {
        if (type == "read")
            return kendo.data.transports["odata"].parameterMap(options, type);
        else {
            if (type == 'create' || type == 'update') {
                data = {}
                for (var i = 0; i < $scope.config.grid.dataSource.transport.data.length; i++) {
                    data[$scope.config.grid.dataSource.transport.data[i]] = options[$scope.config.grid.dataSource.transport.data[i]];
                }
                return kendo.data.transports["odata"].parameterMap(data, type);
            }
        }
    },
},
error: function (e) {
    console.log(e);
},
schema: {
    model: {
        id: $scope.config.grid.model.id,
        fields: $scope.config.grid.model.fields
    },
    data: function (data) {
        if (data.value) {
            return data.value;
        }
        delete data["odata.metadata"];
        return [data];
    },
    total: function (data) {
        if (typeof data.value == 'undefined')
            return data.d;
        return data['odata.count'];
    }
},
pageSize: 30,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
sort: $scope.config.grid.dataSource.sort,

};

批次是真的。 继续出现状态错误的情况:“parsererror” 和errorThrown : SyntaxError:意外的令牌&lt;在位于第4位的JSON位于n.parseJSON(http://localhost:12187/Scripts/jquery/jquery-2.1.1.min.js:4:5309)位于vc(http://localhost:12187/Scripts/jquery/jquery-2.1.1.min.js:4:7397)位于x(http://localhost:12187/Scripts/jquery/jquery-2.1.1.min.js:4:10802)处的XMLHttpRequest处。 (http://localhost:12187/Scripts/jquery/jquery-2.1.1.min.js:4:14767) 信息 : “意外的令牌&lt;在JSON的第4位”

0 个答案:

没有答案