gpt4 book ai didi

javascript - 自定义js树上的图标

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:22:12 25 4
gpt4 key购买 nike

我想添加一个用于关闭和展开的文件夹打开关闭图标和一个用于叶节点的叶图标。

请帮忙

编辑:

尝试添加类型插件,但似乎不起作用。

  var data = {
'core': {
'data': dataObj
},
"search": {
"case_insensitive": true,
"show_only_matches": true
},
"plugins": ["search", "themes"]
};
$('#jstree_category').jstree(data);
$('#jstree_category').on("loaded.jstree", function (e, data) {
_this.treeLoaded = true;
if (!_this.dataFetched) {
return;
}
});
// bind customize icon change function in jsTree open_node event.
$('#jstree_category').on('open_node.jstree', function (e, data) {
$('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first()
.removeClass('glyphicon glyphicon-folder-close').addClass('glyphicon glyphicon-folder-open');
$('#' + data.node.id).find('i.jstree-icon.jstree-themeicon')
.addClass('glyphicon glyphicon-leaf');
});
// bind customize icon change function in jsTree close_node event.
$('#jstree_category').on('close_node.jstree', function (e, data) {
$('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first()
.removeClass('glyphicon glyphicon-folder-open').addClass('glyphicon glyphicon-folder-close');
$('#' + data.node.id).find('i.jstree-icon.jstree-themeicon')
.addClass('glyphicon glyphicon-leaf');
});

enter image description here

最佳答案

这是为你工作的 fiddle 。您应该在 JSON dataObj 中提及节点的类型。

var jsonData = [
{
id : 1,
text : "Folder 1",
type: "root",
state : {
selected : false
},
children : [
{
id : 2,
text : "Sub Folder 1",
type: "child",
state : {
selected : false
},
},
{
id : 3,
text : "Sub Folder 2",
type: "child",
state : {
selected : false
},
}
]
},
{
id: 4,
text : "Folder 2",
type: "root",
state : {
selected : true
},
children : []
}
];

$('#jstree-tree')
.jstree({
core: {
data: jsonData
},
types: {
"root": {
"icon" : "glyphicon glyphicon-plus"
},
"child": {
"icon" : "glyphicon glyphicon-leaf"
},
"default" : {
}
},
plugins: ["search", "themes", "types"]
}).on('open_node.jstree', function (e, data) { data.instance.set_icon(data.node, "glyphicon glyphicon-minus");
}).on('close_node.jstree', function (e, data) { data.instance.set_icon(data.node, "glyphicon glyphicon-plus"); });

JSFiddle

关于javascript - 自定义js树上的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35644534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com