Get updated Kendo Tree View data source

我怕爱的太早我们不能终老 提交于 2019-12-12 19:45:05

问题


I am showing the tree view with a datasource but after dragging and dropping there will be changes and I have to get that changed new datasource. How do I do that?

$.ajax({
         type: "POST",
         url: "TestMenu.aspx/GetMenuData",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (data) {
         $("#treeview").kendoTreeView({
                 dragAndDrop: true,
                 dataSource: $.parseJSON(data.d)
             });
          }
         });

回答1:


So, I finally accomplished the task. Posting answer for anyone who's looking for the same answer as I was.
Changed the call to:

       $.ajax({
           type: "POST",
            url: "TestMenu.aspx/GetMenuData",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $("#treeview").kendoTreeView({
                    dragAndDrop: true,
                    dataSource: $.parseJSON(data.d)
                }).data("kendoTreeView");
            }
        });

Then to get the updated data source:

var treeviewDataSource = $("#treeview").data("kendoTreeView").dataSource.view();



回答2:


We can do with another way:

<div id="treeViewData_Wrapper"></div>
<button onclick="GetNewData()">Get New Data (Refresh kendo TreeView)</button>
<script>
    function FunctionToCreateTreeViewDataSource() {
        // your code here
    }

    function GetNewData() {
        // Clear old treeview html data
        $('#treeViewData_Wrapper').empty();

        // get new treeview html data
        $('<div id="treeViewData"></div>').kendoTreeView({
            dataSource: FunctionToCreateTreeViewDataSource(key, res.data)
        }).appendTo('#treeViewData_Wrapper');
    }
</script>


来源:https://stackoverflow.com/questions/18698039/get-updated-kendo-tree-view-data-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!