【发布时间】:2017-01-25 23:26:19
【问题描述】:
拥有一个以惰性模式加载节点的 Dynatree,有没有办法在子节点“惰性”加载之前告诉他一个节点是父节点?
jQuery(document).ready(function() {
jQuery("#tree").dynatree({
width:300,
title: "Lazy Tree",
keyboard: true,
persist: true,
autoCollapse: true,
clickFolderMode: 3,
fx: {height: "toggle", duration:300},
initAjax: {
type: 'POST',
url: 'treeNodes.php',
dataType: 'json',
data: {key: 0},
},
onActivate: function(node) {
node.toggleExpand();
// Do this and that when some label is clicked
},
onLazyRead: function (node) {
node.appendAjax({
type: 'POST',
url: "treeNodes.php",
dataType: 'json',
data: {key: node.data.key}
});
}
});
});
treeNodes.php 中的 MySQL 请求加载节点:
if ($parent==0) { // Load first level nodes
$req = "SELECT name AS title, id AS 'key', isparent AS isLazy FROM `".$database['database']."`.`".$database['prefix']."categories` WHERE parent=0";
} else { // Load sub-nodes from the given parent
$req = "SELECT name AS title, id AS 'key', isparent AS isLazy FROM `".$database['prefix']."categories` WHERE parent=".$_POST['key'];
}
isparent 列存储节点是否为父节点。
使用它将 isLazy 设置为 1 或 0 告诉树显示可扩展节点。但节点显示为“未知状态”(蓝色菱形图标),直到它们被点击。
我正在寻找与“isParent”节点参数等效的东西,这样,一旦显示,每个节点都会带有一个 [+] 符号(如果它确实有子节点且没有其他符号)。
【问题讨论】:
标签: parent symbols expand dynatree