jstree 简单解决方案之节点换肤

[url=http://www.leutao.com/][img]http://www.leutao.com/templates/default/style/logo.png[/img][/url]

jstree王者归来: QQqun 105564508 希望能与各位在线交流探讨


[color=red][size=large]写在前面 [/size]:[/color]
前一篇文章jstree 简单解决方案,主要讲了jstree的一些基本用法,在这里讨论一下jstree的节点换皮肤。
当然本文还是基于 [color=red][size=medium]jstree 0.99a [/size][/color]版本和 jquery-1.3.2.js为基础写的。



<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery.tree.js"></script>
<script type="text/javascript" language="javascript">
<!--
$(function () {
$.ajaxSetup({cache:false});//ajax调用不使用缓存
$("#vcsTree").tree({//创建树开始
data : {
type : "json",//类型为json
async : true,//动态操作
opts : {
method : "get",
url : "async_json_data2.json"
}
},//end data
ui:{
theme_name : "classic"
},
lang:{
loading : "目录加载中……"
},
rules : {
type_attr : "rel", //设置节点类型
valid_children : "root" // 只有root节点才能作为顶级结点
},
types :{
"default" : {
clickable : true,
draggable : false //设置节点不可拖拽
},
"root" : {
valid_children : "folder", //设置下级节点类型,可是数组
icon : {
image : "root.png"//设置当前节点icon图片,路径自己决定
}
},
"folder" : {
valid_children : "leaf",
icon : {
image : "folder.png"
}
},
"leaf" : {
valid_children : "none",
icon : {
image : "leaf.png"
}
}
}
});
});
//-->
</script>
<div id="container">
<h2 class="title">JsTree</h2>
<div id="vcsTree"></div>
</div>



[color=darkred][size=large]特别提示 [/size]:[/color]

jstree0.99a的 换肤固然简单,但是还是存在bug的,不支持IE6,7系列浏览器,但对firefox,和chrome浏览完全兼容,具体bug修正jstree作者已在最新版jstree1.0进行修正。
如果有已经解决此bug的兄弟,希望能告知一下各位兄弟,把代码贴出来大家学习一下。


[size=medium] [color=red]写在最后:[/color] [/size]

这里是国外的一位哥们对此bug的修正,他并未修改jstree的源代码,只是在jstree初始化代码后添加了一段代码。
[color=violet][size=large]根据他的改写,在IE上不同节点还是不能显示不同的图标,所以感觉 自己 水平有限 ,希望能和各位探讨学习。[/size] [/color]

[size=medium][color=red]仅需修改两处代码:
1. 如注释1处所写,放在tree初始化代码后。
2. 如注释2, 添加在style.css文件内[/color][/size]


Already fixed it with some jquery code:

instead of
//jstree的types设置 ,和上面的代码并无多大区别,只是图片方式和jstree的提取方式是一样的,从一张png图片分割出自己想要的部分(个人说法)。
types : {
"default" : { icon : { image : 'icon.png', position : '0 0' } }
"root" : { icon : { image : 'icon.png', position : '-16px 0' } }
"folder" : { icon : { image : 'icon.png', position : '-32px 0' } }
"page" : { icon : { image : 'icon.png', position : '-32px 0' } }
}

//注释1 ,放在tree初始化代码后
I wrote (after initilization tree)
$("li[rel='root'] > a ins").addClass("root");
$("li[rel='folder'] > a ins").addClass("folder");
$("li[rel='page'] > a ins").addClass("page");

//注释2 ,添加在style.css文件内
and in style.css
.tree-classic li.open a ins.root, .tree-classic li.open a ins.folder, .tree-classic
li.open a ins.page
{background-image:url('icons.png');}
.tree-classic li.open a ins.root{background-position:0 -48px;}
.tree-classic li.open a ins.folder{background-position:0 0;}
.tree-classic li.open a ins.page{background-position:-16px 0;}



在firefox上效果:
[img]http://dl.iteye.com/upload/attachment/270424/19ebb6e7-a712-3031-8202-41def7c0dfa5.png[/img]

[color=red]本代码见附件: themes.rar 请下载使用后记得留言您的更正结果,期待各位的答复[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值