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

物事が更新され、dataSet を更新する必要がある場所:

$('#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'));
        }
    });
});

ここでの問題は、ツリー ビューが更新されることです....しかし、子ノードではありません...

誰でもこれを機能させる方法を知っていますか?

4

1 に答える 1

0

ツリー ビューを完全に再構築しているようです。ツリー ビューのデータ ソースを更新しない理由はありますか?

上記のコードを考えると、これをお勧めします:

treeView.dataSource.read();

また、JSON を取得するサーバーの種類によっては、Kendo データ ソースがデフォルトで GET ステートメントを使用するため、ブラウザが結果をキャッシュできる場合があります。これはサーバー側で修正するか、POST を使用してデータを取得するように切り替えることができます。

read: {
    url: "../api/notifications/byuserid/" + userId,
    contentType: "application/json",
    type: "POST" // Fixes issue if browser was caching GET requests
}
于 2014-05-28T18:24:07.500 に答える