远程数据未从Web服务绑定到网格

时间:2012-12-26 09:09:44

标签: jquery kendo-ui

给出以下代码:

<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>

这里我写了上面的代码行,用于将数据从数据库绑定到kendo Grid 通过网络服务。但是,Data不绑定GridDataSource中是否有任何错误。确保我没有使用Ajax绑定。

1 个答案:

答案 0 :(得分: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 }
]