花式树激活节点启动功能

FancyTree activate function for a node on initiating

本文关键字:启动 功能 节点 激活      更新时间:2023-09-26

我需要一些帮助。我正在尝试以网址为源构建一个花哨的树

        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['激活'] = true;)因此,当我页面加载时,将调用节点的"激活"函数,它将调用我的第二个函数"list_files"

谁能帮我解决这个问题?

谢谢瓦埃尔

您可以在源数据中定义活动状态

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

并在加载数据时触发 activate 事件:

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