【问题标题】:How to render Kendo UI grid from AJAX response data?如何从 AJAX 响应数据呈现 Kendo UI 网格?
【发布时间】:2013-12-23 10:56:01
【问题描述】:

我有这段代码从 static url 获取 json 对象,然后呈现网格。但我想使用作为 AJAX 响应检索的 json 数据,然后使用此响应文本呈现网格。 因为实际部署我不能使用静态 URL。

    $("#grid").kendoGrid({
    dataSource: {
        type: "json",
        transport: {
            read: {url: "http://url/returnsjsonobject.php"}
            //THIS GETS DATA FROM STATIC URL BUT I WANT TO READ DATA AS AJAX RESPONSE
            //like read: somefunctioncall
            //or like read: somevariable
        },
        schema: {
            model: {
                fields: {
                    id: {type: "string", editable: false},
                    name: {type: "string"}

                }
            }
        },
        pageSize: 20
    },
    height: 430
    columns: [
        {field: "id", title: "ID", width: "20px", hidden: "true"},
        "name",
});

提前感谢您的帮助,如果您有任何替代方法;我很乐意尝试。

【问题讨论】:

    标签: javascript jquery ajax kendo-ui kendo-grid


    【解决方案1】:

    请记住,transport.read.url 不必是常量,也可以是函数:

    transport: {
        read: {
            url: function(options) {
                return "somefunctionalcall?id=" + options.id,
            },
            dataType: "json"
    }
    

    甚至将transport.read定义为一个函数:

    transport: {
        read: function (options) {
            $.ajax({
                dataType: "json",
                url: "somefunctionalcall",
                success: function (d) {
                    options.success(d);
                }
            });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      相关资源
      最近更新 更多