简体   繁体   English

如何为树中的选定节点设置CSS类?

[英]How to set a css class for a selected node in a tree?

I am using a Dijit Tree, and I need to change the CSS style for a node when selected (focus). 我正在使用Dijit树,并且在选择(焦点)时需要更改节点的CSS样式。 Lets imagine a node is black when "deselected", and it becames red when "selected" and viceversa. 假设一个节点在“取消选中”时为黑色,而在“选中”时变为红色,反之亦然。

What should I change in my code? 我应该更改我的代码吗?

var tree = new Tree({
                model: this._model,
                showRoot: true,
                autoExpand: true,
                persist: false,
                getLabel: function (item) {
                    return item.name;
                },
                onClick: function (item, node, event) {
                    businessLogic.goToView(item.id);
                }

如果要更新所选节点的css,则应像这样覆盖css: .claro .dijitTreeRowSelected { color: red }这是一个简单的jsfiddle,它将使所选标签变成红色,并将鼠标悬停在一个绿色上: http ://jsfiddle.net/edchat/dox42qye/15/

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

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