Dynamically change icon in fancy tree

…衆ロ難τιáo~ 提交于 2019-12-07 10:51:20

问题


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

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


回答1:


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();
                }
            }
        }
    });


来源:https://stackoverflow.com/questions/29278683/dynamically-change-icon-in-fancy-tree

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