动态更改花式树中的图标 [英] Dynamically change icon in fancy tree

查看:81
本文介绍了动态更改花式树中的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用花式树查看器. https://github.com/mar10/fancytree

I'm using fancy tree viewer. https://github.com/mar10/fancytree

如何根据事件动态更改节点的图标.

How to change the icon of a node dynamically based on an event.

推荐答案

以下代码将在延迟加载后循环遍历所有子节点,并更改子节点的图标(如果子节点是节点而不是文件夹). renderTitle()在这里很重要,因为它告诉节点要重绘并显示新图标.可以将其应用于任何其他事件类型.

The below code will loop through all child nodes after a lazy load, and change the child's icon (if the child is a node and not a folder). The renderTitle() is important here, as this tells the node to be redrawn and show the new icon. This can be applied to any other event type.

    $("#tree").fancytree({
        source: {
            url: "/your/source/url"
        },
        lazyLoad: function(event, data) {
            data.result = {
                url: "/your/lazyload/url"
            };
        },
        loadChildren: function(event, data) {
            var children = data.node.getChildren();

            for (var i = 0; i < children.length; i++) {
                if (!children[i].isFolder()) {
                    children[i].data.icon = "/your/icon.png";
                    children[i].renderTitle();
                }
            }
        }
    });

这篇关于动态更改花式树中的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆