【问题标题】:how can i get array data source, kendo-grid?我怎样才能得到数组数据源,剑道网格?
【发布时间】:2017-04-04 07:20:31
【问题描述】:

我正在获取属性数组,我想在网格中显示所有属性。

怎么做?有可能吗?

这是我的代码:

function StartBuild(ProfileProperties) {
        var details = [];
        for (i = 0; i < ProfileProperties.length; i++) {
            details[i]=[{ name: ProfileProperties[i][0], email: ProfileProperties[i][1], phoneWork: ProfileProperties[i][2], Mobile: ProfileProperties[i][3], ManagerName: ProfileProperties[i][4] }];
        }
             $(document).ready(function () {
            var datasource = new kendo.data.DataSource({
                transport: {
                    type:"odata",
                    read: function (e) {
                        e.success(details);
                    },
                    pageSize: 10,
                    batch: false,
                    schema: {
                        model: {
                            fields: {
                                name: { editable: false },
                                Fname: { editable: false }
                            }
                        }
                    }
                }
            });
            $("#grid").kendoGrid({
                dataSource: datasource,
                pegable: true,
                sortable: {
                    mode: "single",
                    allowUnsort: false
                },
                columns: [{
                    field: "name",
                    title: "name",
                    filterable: {
                        cell: {
                            enabled:true
                        }
                    }
                }, {//[Bild, nameP, email,phonework, Mobile, ManagerName]
                    field: "email",
                    title: "email"
                }, {
                    field: "phoneWork",
                    title: "phoneWork"
                }, {
                    field: "Mobile",
                    title: "Mobile"
                }, {
                    field: "Manager",
                    title: "Manager"
                }],
                filterable: {
                    mode: "row"
                },
            });
        });
    }

只有当我写 details[0] 时它才会显示第一个属性,否则它不会显示任何内容。

【问题讨论】:

  • 请添加您的html

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


【解决方案1】:

看起来有几个问题。

http://dojo.telerik.com/@Stephen/uVOjAk

首先,传输设置不正确。 pageSize、batch 和 schema 不是传输配置的一部分...您需要将它们从传输块中取出,然后将它们放在数据源块中。

你想要:

var datasource = new kendo.data.DataSource({
    transport: {
        type:"odata",
        read: function (e) {
            e.success(details);
        }
    },
    pageSize: 10,
    batch: false,
    schema: {
        model: {
            fields: {
                name: { editable: false },
                Fname: { editable: false }
            }
       }
    }
});

而不是(你所拥有的):

var datasource = new kendo.data.DataSource({
    transport: {
        type:"odata",
        read: function (e) {
            e.success(details);
        },
        pageSize: 10,
        batch: false,
        schema: {
            model: {
                fields: {
                    name: { editable: false },
                    Fname: { editable: false }
                }
            }
        }
    }
});

第二,细节需要是对象数组,不是对象数组的数组。

你想要:

var details = [];
for (i = 0; i < ProfileProperties.length; i++) {
    details.push({ name: ProfileProperties[i][0], email: ProfileProperties[i][1], phoneWork: ProfileProperties[i][2], Mobile: ProfileProperties[i][3], ManagerName: ProfileProperties[i][4] });
}

代替:

var details = [];
for (i = 0; i < ProfileProperties.length; i++) {
    details[i]=[{ name: ProfileProperties[i][0], email: ProfileProperties[i][1], phoneWork: ProfileProperties[i][2], Mobile: ProfileProperties[i][3], ManagerName: ProfileProperties[i][4] }];
}

另外两个不直接导致问题但不正确的问题是:

  1. 您的 dataSource.schema 配置与您的实际数据完全不匹配。架构确实需要匹配实际数据的字段,否则无法匹配配置。
  2. 您在网格配置中拼写错误“pageable”。

【讨论】:

    猜你喜欢
    • 2011-04-11
    • 2015-04-26
    • 1970-01-01
    • 2022-06-13
    • 2013-02-28
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多