2015-09-22 90 views
0

我正在嘗試將XML數據源綁定到KendoGrid。但網格不顯示任何數據。kendo UI如何將xml數據源綁定到KendoGrid

下面是代碼

 var dataSource = new kendo.data.DataSource({ 
     data: '<books><book id="1"><title>Secrets of the JavaScript Ninja</title></book></books>', 
     schema: { 
      // specify the the schema is XML 
      type: "xml", 
      // the XML element which represents a single data record 
      data: "/books/book", 
      // define the model - the object which will represent a single data record 
      model: { 
       // configure the fields of the object 
       fields: { 
        // the "title" field is mapped to the text of the "title" XML element 
        title: "title/text()" 
       } 
      }, 
      schema: { 
       model: { 
       fields: { 
        Title: { editable: false, nullable: true } 

       } 
      } 
      } 
     } 
    }); 


    // alert(errorDataSource.read()); 
    var pc = $("#gridError").kendoGrid({ 
     //excel: { fileName: "Client Orders.xlsx", filterable: true }, 
     dataSource: dataSource, 
     scrollable: true, 
     pageable: true, 
     navigatable: true, 
     columns: [ 
      { command: "destroy", width: 100 }, 
      { 
       title: "Error Message", 
       //lock: true, 
       columns: [ 
        { field: "Title", title: "Error", width: 600, headerAttributes: { class: "k-header-wrap" } } 
       ], 
      } 
     ] 
    }); 

能否請你幫忙。

理想情況下,我想現在顯示基於e.XMLHttpRequest.responseText的錯誤消息;

有沒有簡單的方法將其綁定到Kendo-Grid?

謝謝。

回答

1

請嘗試使用下面的代碼片段。字段名稱'標題'區分大小寫。

<head> 
    <title></title> 
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.common-material.min.css" /> 
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2015.2.902/styles/kendo.material.min.css" /> 

    <script src="https://kendo.cdn.telerik.com/2015.2.902/js/jquery.min.js"></script> 
    <script src="https://kendo.cdn.telerik.com/2015.2.902/js/kendo.all.min.js"></script> 
</head> 
<body> 
    <div id="gridError"></div> 

    <script> 
     var dataSource = new kendo.data.DataSource({ 
      data: '<books><book id="1"><title>Secrets of the JavaScript Ninja</title></book></books>', 
      schema: { 
       // specify the the schema is XML 
       type: "xml", 
       // the XML element which represents a single data record 
       data: "/books/book", 
       // define the model - the object which will represent a single data record 
       model: { 
        // configure the fields of the object 
        fields: { 
         // the "title" field is mapped to the text of the "title" XML element 
         title: "title/text()" 
        } 
       }, 
       schema: { 
        model: { 
         fields: { 
          title: { editable: false, nullable: true } 

         } 
        } 
       } 
      } 
     }); 

     var pc = $("#gridError").kendoGrid({ 
      //excel: { fileName: "Client Orders.xlsx", filterable: true }, 
      dataSource: dataSource, 
      scrollable: true, 
      pageable: true, 
      navigatable: true, 
      columns: [ 
       { command: "destroy", width: 100 }, 
       { 
        title: "Error Message", 
        //lock: true, 
        columns: [ 
         { field: "title", title: "Error", width: 600 } 
        ], 
       } 
      ] 
     }); 

    </script> 
</body> 

讓我知道是否有任何問題。

+0

謝謝Jayesh。它正在工作。非常感謝。 –

相關問題