Friday, November 27, 2009

[jQuery] i found error in jquery.treeview.js

i ask you help me. I found error in jquery.treeview.js....

i get a list of units which have children units. this is links like
this:<a href="" onclick="javascript:clearAsync();getTreeView(7);return
false;">Отдел сопровождения ПЦ</a>

When i click on, i send get param to php server and give :

[{"text": "Блок ИТ","id": "1","expanded": true,"children":[{"text":
"Бочарников Игорь Викторович И.О. Управляющего директора 1075, 1202"},
{"text": "Департамент проектирования информационных систем","id":
"2","expanded": true,"children":[{"text": "Управление по разработке
отчетных и аналитических систем","id": "5","expanded": true,"children":
[{"text": "Отдел систем финансового анализа","id": "18"}]}]}]}]

and then jquery function getTreeView(kodbpod){
$("#async").treeview({
url: "showTreePod.php?kodbpod="+kodbpod
})

} - builds tree and move it into <ul id="async"></ul>. Аnd then
happens something strange.

When at first time builds tree by onclick the tree branches are closed
and open. When clicking the same storage link <a href=""
onclick="javascript:clearAsync();getTreeView(7);return false;">Отдел
сопровождения ПЦ</a> at second time - builds tree but the tree
branches are not closed and not open.
I look the source code on the page and saw this:
1. when tree works:

<ul class="treeview" id="async"><li class="open collapsable
lastCollapsable" id="1"><div title="tree_div" class="hitarea open-
hitarea collapsable-hitarea lastCollapsable-hitarea"></div><div
title="tree_div" class="hitarea open-hitarea collapsable-hitarea
lastCollapsable-hitarea"></div><div title="tree_div" class="hitarea
open-hitarea collapsable-hitarea lastCollapsable-hitarea"></div><span
class="">Блок ИТ</span><ul><li id=""><span><a class=""
href="">Бочарников Игорь Викторович И.О. Управляющего директора
1075, 1202</a></span></li><li class="open collapsable lastCollapsable"
id="2"><div title="tree_div" class="hitarea open-hitarea collapsable-
hitarea lastCollapsable-hitarea"></div><div title="tree_div"
class="hitarea open-hitarea collapsable-hitarea lastCollapsable-
hitarea"></div><div title="tree_div" class="hitarea open-hitarea
collapsable-hitarea lastCollapsable-hitarea"></div><span
class="">Департамент проектирования информационных систем</span><ul
style="display: block;"><li class="open collapsable lastCollapsable"
id="5"><div title="tree_div" class="hitarea open-hitarea collapsable-
hitarea lastCollapsable-hitarea"></div><div title="tree_div"
class="hitarea open-hitarea collapsable-hitarea lastCollapsable-
hitarea"></div><div title="tree_div" class="hitarea open-hitarea
collapsable-hitarea lastCollapsable-hitarea"></div><span
class="">Управление по разработке отчетных и аналитических систем</
span><ul><li class="last" id="18"><span>Отдел систем финансового
анализа</span></li></ul></li></ul></li></ul></li></ul>

2. when tree NOT WORKS:
<ul class="treeview" id="async"><li class="open collapsable
lastCollapsable" id="1"><div title="tree_div" class="hitarea open-
hitarea collapsable-hitarea lastCollapsable-hitarea"></div><div
title="tree_div" class="hitarea open-hitarea collapsable-hitarea
lastCollapsable-hitarea"></div><div title="tree_div" class="hitarea
open-hitarea collapsable-hitarea lastCollapsable-hitarea"></div><div
title="tree_div" class="hitarea open-hitarea collapsable-hitarea
lastCollapsable-hitarea"></div><span class="">Блок ИТ</span><ul><li
id=""><span><a class="" href="">Бочарников Игорь Викторович И.О.
Управляющего директора 1075, 1202</a></span></li><li class="open
collapsable lastCollapsable" id="2"><div title="tree_div"
class="hitarea open-hitarea collapsable-hitarea lastCollapsable-
hitarea"></div><div title="tree_div" class="hitarea open-hitarea
collapsable-hitarea lastCollapsable-hitarea"></div><div
title="tree_div" class="hitarea open-hitarea collapsable-hitarea
lastCollapsable-hitarea"></div><div title="tree_div" class="hitarea
open-hitarea collapsable-hitarea lastCollapsable-hitarea"></div><span
class="">Департамент проектирования информационных систем</
span><ul><li class="open collapsable lastCollapsable" id="5"><div
title="tree_div" class="hitarea open-hitarea collapsable-hitarea
lastCollapsable-hitarea"></div><div title="tree_div" class="hitarea
open-hitarea collapsable-hitarea lastCollapsable-hitarea"></div><div
title="tree_div" class="hitarea open-hitarea collapsable-hitarea
lastCollapsable-hitarea"></div><div title="tree_div" class="hitarea
open-hitarea collapsable-hitarea lastCollapsable-hitarea"></div><span
class="">Управление по разработке отчетных и аналитических систем</
span><ul><li class="last" id="18"><span>Отдел систем финансового
анализа</span></li></ul></li></ul></li></ul></li></ul>

you see? created duplicated DIV. This is mean before create div the
function does not check for an element DIV in DOCUMENT.

this.prepend("<div title=\"tree_div\" class=\"" + CLASSES.hitarea +
"\"/>").find("div." + CLASSES.hitarea).each(function() {
var classes = "";
$.each($(this).parent().attr("class").split(" "), function() {
classes += this + "-hitarea ";
});
$(this).addClass( classes );
});

AND so everytime. even clicks works on odd clicks not working. How
this error fix?
iammultic@gmail.com

No comments: