我怎么刷新了剑道的TreeView一个HierarchicalDataSource?

问题描述 投票:2回答:1

树视图的创建:

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");
    }
}

事情变得更新,我需要刷新的数据集:

$('#btnDelete').on('click', function()
{
    var treeView = $("#treeview").data("kendoTreeView");
    var userId = $('#user_id').val();

    $('#treeview').find('input:checkbox:checked').each(function()
    {
        debugger;
        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()
                    {
                        alert('Delete successful.');
                        //Here is where I try to refresh the data source.
                        CreateNotificationTree(userId);
                    },
                    failure: function()
                    {
                        alert('Delete failed.');
                    }
                });
            treeView.remove($(this).closest('.k-item'));
        }
    });
});

这里的问题是,它刷新树视图....但没有子节点...

任何人都知道如何得到这个工作?

javascript jquery kendo-treeview
1个回答
0
投票

它看起来像你完全重建的树视图。任何理由,你不只是刷新树视图的数据源?

鉴于上面的代码,我会推荐这样的:

treeView.dataSource.read();

此外,根据什么类型的服务器你是从获得JSON,它可能是允许浏览器缓存结果,因为剑道的数据源默认使用GET语句。这可能是固定在服务器端,或者你可以切换到使用POST来检索数据:

read: {
    url: "../api/notifications/byuserid/" + userId,
    contentType: "application/json",
    type: "POST" // Fixes issue if browser was caching GET requests
}
© www.soinside.com 2019 - 2024. All rights reserved.