簡體   English   中英

Kendo數據源未填充到網格中

[英]Kendo datasource is not populating into the grid

我是kendo框架的新手,非常感謝您的幫助,並在需要時提供更多詳細信息。

我正在獲得空網格,我不知道要填充到網格中需要進行哪些更改。

Webservice JSON字符串

{"items":[{"id":1,"publisherName":"Srini","active":false},{"id":2,"publisherName":"Ram","active":false}]}

劍道HTML代碼

<!-- JAVASCRIPT FILES -->
<script src="../bootstrap/js/bootstrap.js"></script>
<script src="../jquery/plug-ins/colorbox-modal/jquery.colorbox.js"></script>
<script src="../jquery/plug-ins/colorbox-modal/colorbox.js"></script>
<script src="../jquery/plug-ins/jquery.placeholder.js"></script>
<script src="../jquery/plug-ins/jquery.jOrgchart.js"></script>      

<script src="../bootstrap/js/bootstrap-prettyCheckable.js"></script>    
<script src="../bootstrap/plug-ins/bootstrap-datepicker.js"></script>   
<script src="../bootstrap/plug-ins/bootstrap-switch.js"></script>
<script src="../bootstrap/js/bootstrap-downloadFile.js"></script>
<script src="../bootstrap/js/bootstrap-select.js"></script>
<!-- Kendo UI Web combined JavaScript -->
<script src="../kendoUI/js/kendo.web.min.js"></script>      



<div id="example">
        <div id="grid"></div>

        <script style="text/javascript">

            $(document).ready(function () {
                var BASE_URL = "",

                    dataSource = new kendo.data.DataSource({
                        dataType: "jsonp",
                        transport: {
                            read:  {
                                url: "http://localhost:8080/wad/admin/searchPublishers.htm",
                                type: "GET",
                                cache: false
                            },
                            update: {
                                url: BASE_URL + "http://localhost:8080/wad/admin/updatePublisher.htm"
                            },
                            create: {
                                url: BASE_URL + "http://localhost:8080/wad/admin/addPublisher.htm"
                            },
                            parameterMap: function(options, operation) {
                                if (operation !== "read" && options.models) {
                                    return {models: kendo.stringify(options.models)};
                                }
                            }
                        },
                        batch: true,
                        pageSize: 20,
                        schema: {
                              model: {
                                  id: "id",
                                  fields: {
                                      id: { editable: false, nullable: true },
                                      publisherName: { validation: { required: true } }
                                  }
                              },
                            data: "items",
                            total: "items.length" //total amount of records. This is needed for paging
                        }
                    });

                $("#grid").kendoGrid({
                    dataSource: dataSource,
                    pageable: true,
                    height: 550,
                    toolbar: ["create"],
                    columns: [
                            { field: "publisherName", title: "Publisher", width: "130px" },
                            { command: ["edit"], title: "Actions", width: "150px" }
                        ],
                    editable: "inline"
                });
            });
        </script>
    </div>

這樣嘗試

像這樣將dataType放入您的transport

如果您使用Cross origin,則僅需使用jsonp否則請使用json

  dataSource = new kendo.data.DataSource({

                        transport: {
                            read:  {
                                url: "http://localhost:8080/wad/admin/searchPublishers.htm",
                                type: "GET",
                                cache: false,
                                dataType: "json"
                            }});

如果您正在獲取json字符串,而不是將代碼行dataType:“ jsonp ”替換為dataType:“ json

您可以使用以下讀取功能

transport: {
      read: function(options) {
        $.ajax( {
          url: "your url",
          dataType: "json",
          success: function(result) {
            options.success(result.items);
          }
        });

      },

您也可以在讀取數據時使用某些參數發布數據,並獲取結果並分配給網格。

transport: {
                read: function(options) {
                    $.ajax({
                        type: "POST",
                        url: "http://sdk.domain.com/services/general.asmx/GetPendingActions",
                        data:  "{'sUsername':'admin@mail.com','sPassword':'13123','sUserID':'1539','sClubID':'1'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (result) {
                            options.success(result);
                        }
                    });
                }
            },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM