2016-02-01 49 views
0

我需要一些幫助。我想用URL建立一個fancytree源FancyTree爲啓動節點啓動功能

 var currentTree = $('#files_tree'); 
     var urlBase = currentTree.attr("data-url"); 
     currentTree.fancytree({ 
     extensions: ["glyph", "dnd"], 
     glyph: {map: glyphIconClasses()}, 
     // selectMode: 1, 

     source: {url: urlBase , 
      data: {mode: "all"}, 
      cache: false 
     }, 
     activate: function (event, data) { 
      //data.node.render();        
      //show_edit_node_fnc(data.node.key); 
      //currentNodeToEdit = data.node; 
      id = data.node.data.id; 
      filesof = data.node.data.filesof;     
      list_files(filesof , id) ; // Call to another JS function 

     }, 

和我使用PHP陣列使內容和發送請求的JSON響應

$arrFileTree['title'] = $project->name; 
    $arrFileTree['folder'] = true;   
    $arrFileTree['expanded'] = true; 
    $arrFileTree['activated'] = true; 

    $arrFileTree['data'] = array("filesof" => "project" , "id" => $project->id); 

    $arrSource = $project->sources ; 
    if($arrSource){ 
     $arrChildren = array(); 
     foreach($arrSource as $source){ 
      $arNode['key'] = $source->id; 
      $arNode['title'] = $source->title; 
      $arNode['folder'] = true; 
      $arNode['data'] = array("filesof" => "source", "id" => $source->id);    
      $arrChildren[] = $arNode; 
     } 
     $arrFileTree['children'] = $arrChildren; 

    } 



    return array($arrFileTree); 

我需要的是,當我加載第一次,一個元素被激活,默認的「激活」函數被調用的一些值我在PHP中分配($ arrFileTree ['activated'] = true;) 因此,當我頁面加載「激活「節點的函數將被調用,並且它會調用我的第二個函數」list_files「

任何人都可以幫助我嗎?

感謝 瓦埃勒

回答

0

你可以在源數據

... 
$arrFileTree['active'] = true; 

定義的活動狀態並觸發時,數據被加載activate事件:

$("#tree").fancytree({ 
    source: { 
     ... 
    }, 
    init: function(event, data) { 
     data.tree.reactivate(); 
    }, 
+0

太感謝你了,這解決了我的問題。 – Wael