我如何获得阵列数据源,剑道网格?

时间:2017-04-04 07:20:31

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

我正在获取一系列属性,我想在网格中显示所有属性。

怎么做?有可能吗?

这是我的代码:

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]时,它才显示第一个属性,否则它不会显示任何内容。

1 个答案:

答案 0 :(得分:0)

看起来有几个问题。

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

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

你想:

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. 你拼写了#34; pageable&#34;网格配置错误。
相关问题