1

给定以下代码:

<script type="text/javascript">
    $(document).ready(function () {
        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    //url:crudurl+"/GetData",
                    url: "GridWebService.asmx/GetData",
                    dataType: "json"
                }
            },
            batch: true,
            pageSize: 4,
            schema: {
                model: {
                    id: "eid",
                    fields: {
                        eid: { editable: false, nullable: true },
                        ename: { validation: { required: true} },
                        age: { type: "number", validation: { required: true, min: 1} },
                        salary: { type: "number", validation: { required: true, min: 1} }
                    }
                }
            }
        });
        $("#grdCRUD").kendoGrid({
            dataSource: dataSource,
            pageSize: 4,
            pageable: {
                refresh: true,
                pageSizes: true
            },
            height: 400,
            toolbar: ["create"],
            columns: [
                        { field: "ename", title: "EmployeeName", width: "150px" },
                        { field: "age", title: "EmployeeAge", width: "150px" },
                        { field: "salary", title: "EmployeeSalary", width: "100px" },
                        { command: ["edit", "destroy"], title: "&nbsp;", width: "210px" }
                     ],
            editable: "inline"
        });
    });                                                                                    
</script>

在这里,我编写了上面的代码行,用于Grid 通过 Web 服务将数据库中的数据绑定到剑道。但是,Data不绑定到Grid. 中是否有任何错误DataSource。确保我没有使用 Ajax 绑定。

4

1 回答 1

0

您的代码似乎正确。确保您的服务将数据作为 JSON 数组返回(打开浏览器并尝试加载http://.../GridWebService.asmx/GetData

您应该会看到如下内容:

[
    {"eid": 1, "ename": "John", "salary":1.2345, "age":23 },
    {"eid": 2, "ename": "Jack", "salary":12.345, "age":34 },
    {"eid": 3, "ename": "Josh", "salary":123.45, "age":45 },
    {"eid": 4, "ename": "Jane", "salary":1234.5, "age":56 }
]
于 2012-12-26T11:12:41.997 回答