0

我需要有关剑道网格的帮助,我调用 Web 服务来填充网格的数据源。它似乎工作正常,但数据未显示在网格中。webservice 调用返回 7 条记录,网格中有 7 行,但它们是空的。

这是代码:

var mime_charset = "application/json; charset=utf-8";
var serverSelectReturnsJSONString = true;
var model_definition = {
    id: "ID",
    fields: {
        customer_id: { type: "number" },
        name_customer: { type: "string" },
        address_customer: { type: "string" }
    }
}

$(document).ready(function () {
    var ds = createJSONDataSource();

    $("#grid").kendoGrid({
        selectable: true,
        theme: "metro",
        dataSource: ds,
        scrollable: true,
        pageable: true,
        // height: 300,
        toolbar: ["save", "cancel"],
        columns: ["ID", "Nome", "Indirizzo"],
        editable: true
    });
    ds.read();
});

这是填充数据源的函数:

function createJSONDataSource() {

    var dataSource = new kendo.data.DataSource({
        severFiltering: true,
        serverPaging: true,
        PageSize: 15,
        //batch: true,
        transport: {
            autoSync: true,
            read: {

                type: "POST",
                url: "WebServices/GetDataTest.asmx/getCustList",
                dataType: "json",
                contentType: mime_charset
            }
        },

        schema: {
            data: function (data) {
                if (data) {
                    if (serverSelectReturnsJSONString)
                        return $.parseJSON(data.d);

                    else
                        return data.d;
                }
            },
            total: function (result) {
                if (!result) return 0;
                var xxx = result.d;
                if (xxx == null) {
                    return result.length || 0;
                }
                if (result.d) {
                    if (serverSelectReturnsJSONString) {
                        var data = $.parseJSON(result.d);

                        return data.length || 0;
                    }
                    else {
                        return result.d.TotalRecords || result.d.length || result.length || 0;
                    }
                }
            },
            model: model_definition
        }
    });
    dataSource.options.schema.parse = function (dataJ) {
        var data;
        data = $.parseJSON(dataJ.d);
        if (data) {
            $.each(data, function (i, val) {
                $.each(model_definition.fields, function (j, col) {
                    if (col.type == "date" || col.type == "datetime") {
                        val[j] = toDate(val[j]);
                    }
                })
            });

            var ret = { d: JSON.stringify(data) };
            return ret;
        }
    }

    dataSource.reader.parse = dataSource.options.schema.parse;

    return dataSource;
}
4

1 回答 1

1

您的columns定义不正确,它是一个数组,但包含对象(不是字符串)。在此处查看文档。如果应该是这样的:

columns: [
    { field: "ID" },
    { field: "Nome" },
    { field: " "Indirizzo" }
],
于 2013-04-29T06:47:46.897 回答