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

发布于 2024-09-01 12:00:09 字数 82 浏览 1 评论 0原文

我创建了一个树,其中包含有关服务器及其虚拟机的信息。 我想将虚拟机的图标更改为绿色(如果虚拟机已打开)或红色(如果虚拟机已关闭)。 如何实现这一目标?

I have created a tree containing information about server and its VMs.
I want to change the icon of VM to green if the VM is power on or to red if the VM is poweroff.
How to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅笑轻吟梦一曲 2024-09-08 12:00:09

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

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 类名。

This might be another way of doing the same thing,

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"};
    }
}

you can also use getIconClass to return appropriate css class name.

滥情哥ㄟ 2024-09-08 12:00:09

创建一个函数来根据虚拟机是否打开或关闭来切换树节点 css 类。

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

创建树时,在构造函数参数中传递 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 以检查 a 中的商店项目。不同的方式...

Create a function to switch the tree node css class depending on if the VM is on or off.

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

When creating your tree, pass the iconFunc in the constructor params:

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

Then create css styles called VmOn and VmOff:

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

The store items that make up the tree nodes will need a property of VmOn or VmOff or change the iconFunc to examine the store items in a different way...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文