如何更改dojo树中叶节点的图标? [英] how to change the icon of leaf node in dojo tree?
问题描述
我已经创建了一个包含有关服务器及其VM的信息的树。
如果虚拟机上电,我想将虚拟机的图标更改为绿色,如果虚拟机处于关机状态,我想将其更改为红色。
如何实现这个?
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?
推荐答案
创建一个函数来切换树节点css类,这取决于VM是打开或关闭。
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";
}
}
});
创建树时,在构造函数params中传递iconFunc:
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);
然后创建名为VmOn和VmOff的css样式:
Then create css styles called VmOn and VmOff:
.VmOn {
background: url(path to your image for VmOn) no-repeat;
构成树节点的商店将需要VmOn或VmOff的属性或更改iconFunc以不同的方式检查商店项目...
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...
这篇关于如何更改dojo树中叶节点的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!