2013-07-24 99 views
2

我通過AJAX加載與劍道UI複雜的樹狀視圖,因爲我需要一個請求加載樹(正常工作):劍道UI重載樹狀

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

function buildTree(){ 
    $.getJSON("admin_get_treedata.php", function (data) { 
     $("#treeview").kendoTreeView({ 
      select: function(item) { editTreeElement(item,'tree'); }, 
      dataSource: data 
     }); 
    }) 
} 

如果我嘗試改變一些後重新加載整個樹數據通過ajax新的構建樹不能正確工作,並且不會更新文本。

$.ajax({ 
     type: 'POST', 
     url: 'ajax/ajax_update_layer.php', 
     data: { 
      layerid:id, 
      ... 
     }, 
     success: function(data){ 
         buildTree(); 
       } 
     }); 

我可以做什麼? 謝謝 斯文

+0

好笑,我嘗試做同樣的事情。我從樹中刪除了一些節點,然後嘗試調用構建它的函數,並且它不像預期的那樣工作。不幸的是,當談到KendoUI技能時,stackoverflow缺乏。 –

回答

0

我有我的工作。

這就是我所做的:創建樹視圖

功能:

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

修改&數據源刷新:

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

希望有所幫助。

2

試試這個Ajax的成功回調

var data = $("#treeView").data('kendoTreeView'); 
    data.dataSource.read();