javascript - 禁用 Kendo-UI TreeView 节点

标签 javascript kendo-ui kendo-treeview

我有一个 TreeView,我想在数据中包含 state_current != null 时禁用某些节点,就像 demo 中的“禁用节点”按钮一样。 。

我的代码是:

<script>
    $(document).ready(function() {

        var treeview = $('#Tree_view').kendoTreeView({
            template: "#= item.name #",
            dataSource: Parcours,
            dataTextField: 'name',
            loadOnDemand: true,
            expand: onExpandedItem
        });
    });

    function onExpandedItem(e) {

        var id_user = @Model.id;

        var item =  $('#Tree_view').data('kendoTreeView').dataItem(e.node)

        var type = item.fields.type;

        if (item.level() > 0) {
            item.id_parcours = item.parentNode().id_parcours;
            if (item.level() == 2) {
                item.id_promo = item.parentNode().id;
            }
        }
        else item.id_parcours = item.Id;

        switch (type) {
            case 'parcours':
                item.children.transport.options.read = {
                    url: '@Url.Action("Get_Session", "Users")' + '?user_id=' + id_user,
                    dataType: "json",
                };
                break;

            case 'session':
                item.children.transport.options.read = {
                    url: '@Url.Action("Get_Matiere")' + '?user_id=' + id_user,
                    dataType: "json"
                };
                break;

            default:
                break;
        }
    }

    var Matiere = {
        transport: {
            read: {
                url: '@Url.Action("Get_Matiere")',
                type: 'GET',
                dataType: 'json'
            }
        },
        schema: {
            model: {
                fields: {
                    name: 'Name',
                    type: 'matiere'
                },
                hasChildren: false,
            }
        }
    }

    var Session = {
        transport: {
            read: {
                url: '@Url.Action("Get_Session")',
                type: 'GET',
                dataType: 'json'
            }
        },
        schema: {
            model: {
                fields: {
                    id: 'IdPromo',
                    name: 'NamePromo',
                    type: 'session',
                    date: 'Date',
                    state: 'State_current',
                },
                hasChildren: true,
                children: Matiere
            }
        }
    }

    var Parcours = {
        transport: {
            read: {
                url: '@Url.Action("Get_Parcours", "Users")',
                data: {user_id: @Model.id},
                type: 'GET',
                dataType: 'json'
            }
        },
        schema: {
            model: {
                fields: {
                    id: 'Id',
                    name: 'Name',
                    type: 'parcours'
                },
                hasChildren: true,
                children: Session
            }
        }
    };
</script>

最佳答案

在您想要禁用节点的地方执行此操作

var selectedNode = treeview.select();
    treeview.enable(selectedNode, false);

这里的 Treeview 应该是你的 Treeview 对象,创建 Treeview 后你可以如下选择它。您可以提供需要禁用的节点,而不是 selectedNode。

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

如果您想在 Treeview 首先呈现时执行此操作,您可以在 kendoTreeView 数据绑定(bind)事件中检查此操作,或者如果您希望在选择时在 select 事件中检查此操作。

关于javascript - 禁用 Kendo-UI TreeView 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39170046/

相关文章:

javascript - jQuery Sortable 不能拖放

javascript - 为什么 JS 允许在数组中使用负索引?

javascript - onclick 使不显示和阻止的麻烦

javascript - 使用 JavaScript 从 HTML 元素中删除类

jquery - 当loadOnDemand设置为true时如何从kendoTreeInstance.dataSource.get获取数据项

javascript - 访问所选 Kendo TreeView 节点的子节点

javascript - Kendo Treeview : Can I temporarily disable ondemand loading?

c# - Kendo 日历中突出显示的日期仅在警报时有效

css - Kendo Mobile - 模态视图不调整内容的高度

javascript - kendo ui 列表框删除项目