gpt4 book ai didi

javascript - 节点启动时的 FancyTree 激活函数

转载 作者:行者123 更新时间:2023-11-30 16:18:22 27 4
gpt4 key购买 nike

我需要一些帮助。我正在尝试构建一个以 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”

谁能帮我解决这个问题?

谢谢威尔

最佳答案

您可以在源数据中定义事件状态

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

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

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

关于javascript - 节点启动时的 FancyTree 激活函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35133184/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com