dojo小例子(22)自定义dijit Tree的节点图标

本文深入解析了dojo官网API中关于树的节点图标自定义实现的代码逻辑,详细介绍了如何根据节点类型获取相应的图标类名,并讨论了对于未定义类型的节点使用默认对象图标的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

tree.getIconClass = function (item, /*Boolean*/ opened) {
  var type = item.type.toLowerCase();
  if (type === "folder") {
	return opened ? "dijitFolderOpened" : "dijitFolderClosed";
  } else {
	// Lots of modules are marked as type undefined, for which we have no icon, so use object instead.
	// TODO: we also have no icon for instance, so use object icon.
	if (/undefined|instance/.test(type)) {
		type = "object";
	}
	return "icon16 " + type + "Icon16";
  }
}
.stringIcon,
.stringIcon16{ background-image:url('icons/16x16/string.png'); }

.icon16{ width: 16px; height: 16px; }
dojo官网API的树的节点图标就是自定义的,以上代码就来自官网API的源码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值