2013-07-29 84 views
0
<ArrayOfNode xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://....Controllers"> 
    <Node> 
     <notificationType>Test1 (20)</notificationType> 
     <notifications xmlns:d3p1="http://...Serialization/Arrays"> 
      <d3p1:string>3298</d3p1:string> 
      <d3p1:string>983932</d3p1:string> 
      ... (20 items here) 
    </Node> 
    <Node> 
     <notificationType>Test2 (40)</notificationType> 
     <notifications xmlns:d3p1="http://...Serialization/Arrays"> 
      <d3p1:string>ABCD</d3p1:string> 
      <d3p1:string>AZYX</d3p1:string> 
      ...(40 items here) 
    </Node> 
</ArrayOfNode> 

這不是工作:如何在Kendo UI樹視圖中加載以下HTTP響應?

var notificationTypes = new kendo.data.HierarchicalDataSource({ 
       transport: { 
        read: { 
         url: "http://..." 
        } 
       }, 
       schema: { 
        model: { 
         notificationType: "notificationType", 
         notifications: "notifications", 
         children: "notifications", 
         string: "string", 
         hasChildren: true 
        } 
       } 
      }); 

      $("#treeview").kendoTreeView({ 
       dataSource: notificationTypes, 
       checkboxes: { 
        checkChildren: true 
       }, 
       dataTextField: ["notificationType", "notifications"] 
      }); 

只加載父節點,但我想使每個節點的「通知」兒童項目的樹。

它應該是這樣的:

  • Test1的(20)

- 3298

- 983932

  • 的Test2(40)

- ABCD

- 983932

+0

我認爲你缺少架構中的子對象。你有沒有嘗試使用KendoUI服務器包裝?讓生活變得更容易, – Nilesh

+0

你能告訴我一個例子嗎? –

+0

我現在沒有示例,因爲我正在旅行,無法訪問代碼!如果你有一個帳戶,你可以訪問KendoUI網站並下載最新的二進制文件。當我訪問代碼庫時,我會嘗試發佈一些示例代碼。 – Nilesh

回答

1

我有固定的問題。

這裏的腳本代碼:

<script language="javascript" type="text/javascript"> 
      $(function() 
      { 
       var data = new kendo.data.HierarchicalDataSource({ 
        transport: { 
         read: { 
          url: "../api/notifications/byuserid/10078261", 
          contentType: "application/json" 
         } 
        }, 
        schema: { 
         model: { 
          children: "notifications" 
         } 
        } 
       }); 

       $("#treeview").kendoTreeView({ 
        dataSource: data, 
        checkboxes: { 
         checkChildren: true 
        }, 
        dataTextField: ["notificationType", "NotificationDesc"] 
       }); 
      }); 
     </script> 

而這裏的API:

namespace X.Controllers 
{ 
    public class NotificationsController : ApiController 
    { 
     public List<Node> getNotifications(int id) 
     { 
      var bo = new HomeBO(); 
      var list = bo.GetNotificationsForUser(id); 
      var notificationTreeNodes = (from GBLNotifications n in list 
             where n.NotificationCount != 0 
             select new NotificationTreeNode(n)).ToList(); 
      var li = notificationTreeNodes.Select(no => new Node 
      { 
        notificationType = no.NotificationNode.NotificationType + " " + "(" + no.NotificationNode.NotificationCount + ")", notifications = bo.GetNotificationsForUser(id, no.NotificationNode.NotificationTypeId).Cast<GBLNotifications>().Select(item => new Notification 
        { 
          ID = item.NotificationId, NotificationDesc = item.NotificationDescription 
        }).ToList() 
      }).ToList(); 
      return li; 
     } 
    } 

    public class Node 
    { 
     public List<Notification> notifications; 

     public string notificationType 
     { 
      get; 
      set; 
     } 
    } 

    public class Notification 
    { 
     public int ID 
     { 
      get; 
      set; 
     } 

     public string NotificationDesc 
     { 
      get; 
      set; 
     } 
    } 
} 
相關問題