gpt4 book ai didi

jquery - JsTree:如何对顶部文件夹的 jstree 节点进行排序

转载 作者:行者123 更新时间:2023-12-03 22:58:18 26 4
gpt4 key购买 nike

我使用插件 Jstree 绘制文件夹和文件树。

我想获取顶部的文件夹列表,然后获取文件列表(文件夹和文件列表必须按字母顺序排序)。

这是我的树初始化函数:

$('#jstree_demo_div').jstree({ 
'core' : {
'data' : [

{"id":"index_0","text":"test_folder","parent":"#","icon":""},
{"id":"index_1","text":"vide","parent":"index_0","icon":""},
{"id":"index_2","text":"05nesf-sdfdgd.mp4","parent":"index_1","icon":"fa fa-film"},
{"id":"index_3","text":"naissance-d-une-fleur-ouwzp9me-41.mp4","parent":"index_0","icon":"fa fa-film"},
{"id":"index_4","text":"za05nesfsdfsdg.mp4","parent":"index_0","icon":"fa fa-film"},
{"id":"index_5","text":"ddd","parent":"#","icon":""},
{"id":"index_6","text":"05nes-ibw6q9me-41.mp4","parent":"index_5","icon":"fa fa-film"},
{"id":"index_7","text":"tom-jerry-soundscape-ttar8gme-41.mp4","parent":"#","icon":"fa fa-film"},
{"id":"index_8","text":"aaes-qmc8q-9me-41.mp4","parent":"#","icon":"fa fa-film"},
{"id":"index_9","text":"bb05nes.mp4","parent":"#","icon":"fa fa-film"}
]
},
'plugins' : ['sort','types'],
'sort' : function(a, b) {
//What is the function of sorting
},
});

我的初始化结果: Tree

我需要使用什么排序功能?

最佳答案

您可以按图标排序,然后按文本排序:

'sort' : function(a, b) {
a1 = this.get_node(a);
b1 = this.get_node(b);
if (a1.icon == b1.icon){
return (a1.text > b1.text) ? 1 : -1;
} else {
return (a1.icon > b1.icon) ? 1 : -1;
}

这是一个jsfiddle

关于jquery - JsTree:如何对顶部文件夹的 jstree 节点进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41061535/

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