2016-12-09 5 views
5

플러그인 Jstree를 사용하여 ans 파일 폴더 트리를 그립니다.JsTree : 맨 위에있는 폴더가있는 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

내가 사용할 필요가 정렬 어떤 기능이?

당신은 텍스트로 아이콘으로 이후 정렬 할 수 있습니다

답변

6

: 여기

'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

입니다