如何从Kendo TreeView中删除选中的节点?

时间:2013-07-31 18:28:07

标签: javascript jquery kendo-treeview

这是我的配置:

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

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

在“删除”按钮的点击事件中,我想删除所有已检查的节点。

$(document).ready(function()
{
    $('#btnDelete').click(function()
    {
        var treeView = $('#treeview').data("kendoTreeView");
        var selectedNodes = treeView.select();
        //here's where im not sure what to do...
    });
});

树视图在这里是标记(我知道一团糟......我现在正在解决所有这些混乱的人):

<body onload=" Resize(); ">
   <form id="frmTake2Home" runat="server">
       <table class="main" style="border-style: hidden; padding: 0px">
          <td class="tbody">
             <table style="border-spacing: 0px; border-style: hidden; padding: 0px; vertical-align: top" width="100%" border="0">
              <tr>
                <td id="tdTreeView" valign="top" width="48%">
                <tr>
                  <td colspan="2">
                    <div id="treeview"></div> //here's my kendo treeview

1 个答案:

答案 0 :(得分:3)

<强>更新

$(document).ready(function(){

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

    $('#btnDelete').on('click', function(){
        $('#treeview').find('input:checkbox:checked').each(function(){
            treeView.remove($(this).closest('.k-item'));
        });
    });

});