Kendo UI reload treeview

前端 未结 2 1589
说谎
说谎 2021-01-21 11:00

I load a complex treeview with kendo ui via ajax because I need to load the tree with one request (works fine):

$(document).ready(function() {    
    buildTree(         


        
相关标签:
2条回答
  • 2021-01-21 11:26

    try this on ajax success callback

    var data = $("#treeView").data('kendoTreeView');
        data.dataSource.read();
    
    0 讨论(0)
  • 2021-01-21 11:36

    I got mine to work.

    This is what I did:

    Function that creates the tree view:

    function CreateNotificationTree(userId)
    {
        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 $item = this.dataItem(e.node);
            window.open($item.NotificationLink, "_self");
        }
    }
    

    Modification & data source refresh:

    $('#btnDelete').on('click', function()
    {
        var treeView = $("#treeview").data("kendoTreeView");
        var userId = $('#user_id').val();
    
        $('#treeview').find('input:checkbox:checked').each(function()
        {
            var li = $(this).closest(".k-item")[0];
            var notificationId = treeView.dataSource.getByUid(li.getAttribute('data-uid')).ID;
    
            if (notificationId == "undefined")
            {
                alert('No ID was found for one or more notifications selected. These notifications will not be deleted. Please contact IT about this issue.');
            }
            else
            {
                $.ajax(
                    {
                        url: '../api/notifications/deleteNotification?userId=' + userId + '&notificationId=' + notificationId,
                        type: 'DELETE',
                        success: function()
                        {
                            CreateNotificationTree(userId);
                            alert('Delete successful.');
    
                        },
                        failure: function()
                        {
                            alert('Delete failed.');
                        }
                    });
                treeView.remove($(this).closest('.k-item'));
            }
        });
    });
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题