如何将此JSON绑定到Kendo UI TreeView?

时间:2013-07-27 00:39:36

标签: c# jquery kendo-ui

JSON / XML返回:

<ArrayOfNode xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DGA.Take2.WebUI.Controllers">
     <Node>
          <notificationType>NZY (1)</notificationType>
          <notifications xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                <d3p1:string>notification1</d3p1:string>
                <d3p1:string>notification2</d3p1:string>
                <d3p1:string>notification3</d3p1:string>
          </notifications>
     </Node>
</ArrayOfNode>

我正在尝试将此树加载到Kendo UIs TreeView中:

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

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

问题在于:

1 个答案:

答案 0 :(得分:2)

了解如何操作:

function CreateNotificationTree(userId)
{
    debugger;
    var data = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "../api/notifications/byuserid/" + userId,
                contentType: "application/json"
            }
        },
        schema: {
            model: {
                children: "notifications"
            }
        }
    });

    $("#treeview").kendoTreeView({
        dataSource: data,
        loadOnDemand: true,
        dataUrlField: "LinksTo",
        checkboxes: {
            checkChildren: true
        },
        dataTextField: ["notificationType", "NotificationDesc"],
        select: treeviewSelect
    });

    function treeviewSelect(e)
    {
        var node = this.dataItem(e.node);
        window.open(node.NotificationLink, "_self");
    }
}