如何在dojo树中更改叶节点的图标?

时间:2010-05-14 06:16:39

标签: dojo tree

我创建了一个包含有关服务器及其VM的信息的树。 我想在VM启动时将VM的图标更改为绿色,如果VM处于断电状态,则将其更改为红色。 怎么做到这一点?

2 个答案:

答案 0 :(得分:3)

这可能是做同样事情的另一种方式,

getIconStyle:function(item, opened){
    if(!item.root){
        if(!item.children){
            // Style the nodes that not have childrens
            return {backgroundColor: "red"};
        }else{
            // Style the nodes that have childrens
            return {backgroundColor: "blue"};
        }
    }else{
        // Style the root node here
        return {backgroundColor: "orange"};
    }
}

您也可以使用getIconClass返回适当的css类名。

答案 1 :(得分:0)

创建一个函数来切换树节点css类,具体取决于VM是打开还是关闭。

ar iconFunc = dojo.hitch(this, function (item, opened) { 
                if(item !== undefined && item !== null) {
                    if (item.VmOn!== undefined) {
                        return "VmOn";
                    }
                    else {
                        return "VmOff";
                    }
                }
            });

创建树时,在构造函数params中传递iconFunc:

var treeParams = {
    getIconClass : iconFunc, //attach the custom icon function
...};
var myTree = new dijit.Tree(treeParams);

然后创建名为VmOn和VmOff的css样式:

.VmOn {
    background: url(path to your image for VmOn) no-repeat;

构成树节点的商店项目需要VmOn或VmOff属性,或者更改iconFunc以不同的方式检查商店项目......

相关问题