在KendoUI数据源中获取更新请求的字符串

Getting a string on an update request in KendoUI datasource

本文关键字:请求 字符串 更新 获取 KendoUI 数据源      更新时间:2023-09-26

我有一个非常简单的网格,数据源可以正确检索数据因为我有一个图式。解析函数定义

问题是,当我尝试更新/创建新行schema.parse()再次调用和传递给它的参数是一个字符串,包含我的页面的HTML。真搞不懂这到底是怎么回事。由于

  var _dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                dataType: "json",
                url: layerDefProvider.getLayerUrlById("surveys") + "/query",
                data: {
                    f: "json",
                    //token: token,
                    outFields: "*",
                    //outSR: 3857,
                    where: "1=1"
                },
                type: "POST"
            },
            create: function (options) {
                console.debug("called");//never gets called
            },
            update: function (options) {
                console.debug("called");//never gets called
            },
            destroy: function (options) {
                console.debug("called");//never gets called
            }
        },
        filter: {
            field: "OBJECTID", operator: "eq", value: 0
        },
        schema: {
            data:function(response) {
            },
            parse: function (data) {//on loading it is fine, on updating the data param is a string of my HTML of the page
                var rows = [];
                var features = data.features;
                if (!features) {
                    return [];
                }
                for (var i = 0; i < features.length; i++) {
                    var dataRow = {};
                    dataRow.OBJECTID = features[i].attributes.OBJECTID;
                    dataRow.Name = features[i].attributes.Name;
                    dataRow.Date = features[i].attributes.Date;
                    dataRow.Comment = features[i].attributes.Comment;
                    rows.push(dataRow);
                }
                return rows;
            },
            model: {
                id: "OBJECTID",
                fields: {
                    OBJECTID: { type: "number", editable: false },
                    Name: { type: "string" },
                    Date: { type: "string" },
                    Comment: { type: "string" }
                }
            }
        }
    });
    var _surveysPicker = $(config.table).kendoGrid({
        toolbar: ["create","save"],
        editable: true,
        dataSource: _dataSource,
        height: 300,
        sortable: true,
        selectable: "multiple",
        columnMenu: true,
        resizable: true,
        columns: [{
            field: "OBJECTID",
            width: 40
        }, {
            field: "Name",
            width: 40
        }, {
            field: "Date",
            width: 40
        }, {
            field: "Comment",
            width: 100
        }]
    });

如果您只需要在read操作中解析数据,则需要将解析函数移动到read事件中。