带有 SharePoint 列表项的 Telerik Kendo UI

问题描述 投票:0回答:1

我正在尝试使用 Telerik Kendo UI 创建一个网格,它将显示 SharePoint 数据。为了获取数据,我使用 SharePoint oData 服务。

我在这里找到了类似功能的示例:http://demos.telerik.com/kendo-ui/grid/remote-data-binding

并尝试了下面的代码

<!DOCTYPE html>
<html>
<head>
    <base href="http://demos.telerik.com/kendo-ui/grid/remote-data-binding">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.1.226/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.1.226/styles/kendo.material.min.css" />

    <script src="//kendo.cdn.telerik.com/2016.1.226/js/jquery.min.js"></script>
    <script src="//kendo.cdn.telerik.com/2016.1.226/js/kendo.all.min.js"></script>
</head>
<body>

        <div id="example">
            <div id="grid"></div>
            <script>
                $(document).ready(function() {
                    $("#grid").kendoGrid({
                        dataSource: {
                            type: "odata",
                            transport: {
                                read: "http://server/_api/Web/Lists(guid'guid of list')/Items"
                            },
                            schema: {
                                model: {
                                    fields: {
                                        Title: { type: "string" }
                                    }
                                }
                            },
                            pageSize: 20,
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        height: 550,
                        filterable: true,
                        sortable: true,
                        pageable: true,
                        columns: [{
                                field:"Title"
                            }
                        ]
                    });
                });
            </script>
</div>


</body>
</html>

出现以下错误

拒绝执行脚本 'http://server/_api/Web/Lists(guid'listguid50387715207_1459178447636&%24inlinecount=allpages&%24format=json&%24top=20' 因为它的 MIME 类型('application/atom+xml')不可执行,并且 启用严格的 MIME 类型检查。

sharepoint telerik kendo-grid odata telerik-grid
1个回答
3
投票

您可能想将传输属性更改为

transport: {
    read: {
        url: "http://server/_api/Web/Lists(guid'guid of list')/Items",
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Accept", "application/json; odata=verbose")
        }
    }
}

为了强制sharepoint返回json-data而不是atom+xml(如果你省略accept-header,这是默认的)。

© www.soinside.com 2019 - 2024. All rights reserved.