1

i need some help. I am trying to build a fancytree with url as source

        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

        },

and i make the content using php array, and send the request as json response

    $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);

what I need is, when i load the page for the first time, that an element be activated and the default "activate" function to be called on some value i assigned in php like ($arrFileTree['activated'] = true;) So when i page loaded the "activate" function for a node will be called, and it will call my second function "list_files"

could anyone help me with this ?

Thanks Wael

Wael
  • 455
  • 1
  • 4
  • 17

1 Answers1

2

You could define the active state in the source data

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

and trigger the activate event when the data was loaded:

$("#tree").fancytree({
    source: {
        ...
    },
    init: function(event, data) {
        data.tree.reactivate();
    },
mar10
  • 14,320
  • 5
  • 39
  • 64