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

时间:2015-06-02 18:07:14

标签: javascript kendo-ui kendo-grid kendo-datasource

我有一个非常简单的网格,其数据源可以正确地检索数据 因为这个原因我定义了一个schema.parse函数

问题在于,当我尝试更新/创建新行时,再次调用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
        }]
    });

1 个答案:

答案 0 :(得分:0)

如果只需要在读取操作上解析数据,则需要在读取事件中移动解析函数。