php/mysql 구현을 사용할 때 jsTree에 루트 노드를 표시해야합니다. 모든 관련 코드는 출력의 스크린 샷과 함께 아래에 있습니다.jsTree PHP를 사용하여 MySQL에서 데이터를 채울 때 루트 노드 표시
이현재 테이블 구조 : http://i.imgur.com/RpDZw.jpg
전류 출력 (미안 이미지를 포함 ... 아직 없습니다) : 당신은 ROOT라는 실제 루트 노드를 볼 수 있듯이 http://i.imgur.com/5Gh6M.jpg
을에 표시되지 않습니다 나무. 위의 표시입니다 코드의 다양한 조각 :
자바 스크립트 :
.jstree({
// List of active plugins
"plugins" : [
"themes","json_data","ui","crrm","dnd","search","types","hotkeys","contextmenu"
],
// I usually configure the plugin that handles the data first
// This example uses JSON as it is most common
"json_data" : {
// This tree is ajax enabled - as this is most common, and maybe a bit more complex
// All the options are almost the same as jQuery's AJAX (read the docs)
"ajax" : {
// the URL to fetch the data
"url" : "_demo/server2.php",
// the `data` function is executed in the instance's scope
// the parameter is the node being loaded
// (may be -1, 0, or undefined when loading the root nodes)
"data" : function (n) {
// the result is fed to the AJAX request `data` option
return {
"operation" : "get_children",
"id" : n.attr ? n.attr("id").replace("node_","") : 1
};
}
}
},
PHP : 당신은 자바 스크립트에서 볼 수 있듯이
function get_children($data) {
$tmp = $this->_get_children((int)$data["id"]);
if((int)$data["id"] === 1 && count($tmp) === 0) {
## - No data returned
}
$result = array();
if((int)$data["id"] === 0) return json_encode($result);
foreach($tmp as $k => $v) {
$result[] = array(
"just_id" => $k,
"attr" => array("id" => "node_".$k, "rel" => $v[$this->fields["type"]]),
"data" => $v[$this->fields["title"]],
"owner" => $v[$this->fields["owner"]],
"state" => ((int)$v[$this->fields["right"]] - (int)$v[$this->fields["left"]] > 1) ? "closed" : ""
);
}
return json_encode($result);
}
function _get_children($id, $recursive = false) {
$hbhbhbh = fSession::get('nodes_allowed[nodes]');
if (in_array($id, $hbhbhbh)) {
$children = array();
if($recursive) {
$node = $this->_get_node($id);
$this->db->query("SELECT `".implode("` , `", $this->fields)."` FROM `".$this->table."` WHERE `".$this->fields["left"]."` >= ".(int) $node[$this->fields["left"]]." AND `".$this->fields["right"]."` <= ".(int) $node[$this->fields["right"]]." ORDER BY `".$this->fields["left"]."` ASC");
}
else {
$this->db->query("SELECT `".implode("` , `", $this->fields)."` FROM `".$this->table."` WHERE `".$this->fields["parent_id"]."` = ".(int) $id." AND FIND_IN_SET(".$this->fields["owner"].", '".implode(',', fSession::get('nodes_allowed[nodes_visible]'))."') ORDER BY `".$this->fields["position"]."` ASC");
}
while($this->db->nextr()) $children[$this->db->f($this->fields["id"])] = $this->db->get_row("assoc");
return $children;
} else {
$children = array();
return $children;
}
}
, 나는 처음에 부하에 노드 1을 요청하고있다. 하지만 노드 바로 아래에 노드 만 보여줍니다. 처음에 트리 아래로 다른 노드를로드하면 (실제로 해당 노드가 루트 노드가됩니다) 노드 아래에 모든 하위 노드가로드되지만 초기 노드는 표시되지 않습니다.
누군가가 올바른 방향으로 나를 가리킬 수 있다면, 나는 정말로 감사 할 것입니다. 트리가로드 될 때 같은 문제 ..
을 가진 다른 사람들을위한
감사 앨런