单击jstree上的更改图标 [英] Change icon on click jstree
问题描述
我有使用jstree插件的代码。
I have this code using jstree plugin.
$(".gems-tree").on('changed.jstree' , function( event , data ){
console.log("folder clicked");
});
并且它有效,但现在我想将文件夹中的图标更改为关闭打开,是有办法实现这个目标吗?
And it works, but now i want to change the icon from the folder to close to open, is there a way to achive this?
注意
已经尝试使用 data.node.state.opened = true
只是为了查看文件夹图标是否发生变化。
Already try with data.node.state.opened = true
just to see if the folder icon change but not.
推荐答案
如果您需要更改每个所选节点的图标,Adnan Y的答案将有效(只需确保 data.action
select_node
):
If you need to change the icon of each selected node, the answer by Adnan Y will work (just make sure data.action
is "select_node"
):
$("#jstree2").on('changed.jstree', function(evt, data) {
if(data.action === "select_node") {
data.instance.set_icon(data.node, 'http://jstree.com/tree-icon.png');
}
});
如果您需要对节点打开和关闭做出反应,请使用类似的代码:
If you need to react on nodes opening and closing, use similar code:
$("#jstree2")
.on('open_node.jstree', function(evt, data) {
data.instance.set_icon(data.node, 'http://jstree.com/tree-icon.png');
})
.on('close_node.jstree', function(evt, data) {
data.instance.set_icon(data.node, true);
});
在第二个示例中,图标设置为 true
- 这会将其恢复为默认图标(如果这是你需要的)。
In the second example the icon is set to true
- this will restore it to the default icon (if this is what you need).
这篇关于单击jstree上的更改图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!