启动

时间:2016-02-01 14:36:21

标签: javascript fancytree

我需要一些帮助。我正在尝试用url构建一个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'] =真正;) 因此,当我加载页面时,将调用节点的“激活”功能,它将调用我的第二个函数“list_files”

任何人都可以帮我这个吗?

由于 瓦埃勒

1 个答案:

答案 0 :(得分:2)

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

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

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

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