简体   繁体   English

根据类型更改jstree节点文本颜色

[英]Change jstree node text colour based on type

I have been searching the interent for an age and couldnt find an answer. 我一直在搜索互联网一个年龄,但无法找到答案。 I was trying to change node text colour dependant on the type of the particular node. 我试图根据特定节点的类型更改节点文本颜色。 So in this example i wanted to change the text colour of every node that is a "Role" type defined in data. 因此,在此示例中,我想要更改数据中定义的“角色”类型的每个节点的文本颜色。

    $("#roleTree").jstree({
        json_data: {
            data: roleTreeData
        },
        "themes": {
            "theme": "default",
            "dots": true,
            "icons": false
        },
        "ui": {
            "select_limit": 1,
            "select_multiple_modifier": "none"
        },
        "types": {
            "types": {
                "AM": {
                    "hover_node": false,
                    "select_node": false
                },
                "AF": {
                    "hover_node": false,
                    "select_node": false
                },
                "Role": {
// i dont know if possible to be done here? add class?
             //   this.css("color", "red")
                    //{ font-weight:bold}
                }
            }
        },

        plugins: ["themes", "json_data", "ui", "Select", "types", "crrm"]

    }).bind("loaded.jstree", function (event, data)
    {
        $("#roleTree").jstree("open_all");
         data.inst.select_node('ul > li:first');

    }).bind("select_node.jstree", function (event, data)
    {
        selectedRoleId = data.rslt.obj.attr("id");
        window.selectedRole = GetRole(selectedRoleId);              
    });
}

Or any other method to highlight or tell users that only the role is selectable. 或者任何其他方法来突出显示或告诉用户只有角色是可选择的。

This can be done using the following CSS, assuming you are using the default classic theme. 假设您使用的是默认的经典主题,则可以使用以下CSS完成此操作。

.jstree-classic li[rel="Role"] > a { color:red; }

Get jstree-classic class, where child li has rel attribute of Role , get the first child a of that li and assign color to red. 获取jstree-classic类,其中child li具有Role rel属性,获取该li的第一个子a并将颜色指定为红色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM