0

我有一个 Treeview 可以在页面加载时正常加载,但我想将树过滤到选定的节点,所有功能似乎都在 100% 工作,但是当我尝试应用过滤器时它没有在树上显示任何内容即使 json 正在返回。我希望我说得通。这是我的代码:

<div id="treeview"></div>
<script>
    var selectedId;

    var homogeneous = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "/loadtree",
                dataType: "json"
            }
        },
        schema: {
            model: {
                id: "Id",
                hasChildren: "hasChildren"
            }
        }
    });

    $("#treeview").kendoTreeView({
        dataSource: homogeneous,
        dataValueField: "Id",
        dataTextField: "Name",
        select: onSelect

    });



    function onSelect(e) {
        var tv = $("#treeview").data("kendoTreeView").dataItem(e.node);
        $("#details-container").load("entitydetail/" + tv.Id);
        selectedId = tv.Id;

    }

    function loadTreetoSelected()
    {

        newdata = new kendo.data.HierarchicalDataSource({
            transport: {
                read: {
                    url: "/loadtreetoselected/" + selectedId,
                    dataType: "json",
                }

            },
            schema: {
                model: {
                    id: "Id",
                    hasChildren: "hasChildren"
                }
            }
        });

        $("#treeview").data("kendoTreeView").setDataSource(newdata);    

    }       

</script>

<input type="button" value="Filter to Selected" onclick="javascript: loadTreetoSelected();" />

这是返回的json:

{"Id":7932,"Name":"OPC 2013","hasChildren":true}

谢谢你的帮助

4

0 回答 0