2

我正在显示带有数据源的树视图,但拖放后会有更改,我必须获取更改后的新数据源。我怎么做?

$.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)
             });
          }
         });
4

2 回答 2

9

所以,我终于完成了任务。为正在寻找与我相同答案的任何人发布答案。
将调用更改为:

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

然后获取更新的数据源:

var treeviewDataSource = $("#treeview").data("kendoTreeView").dataSource.view();
于 2013-09-10T10:58:49.813 回答
1

我们可以用另一种方式:

<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>
于 2019-09-29T03:30:09.557 回答