OdinaSpb / jstree

Automatically exported from code.google.com/p/jstree
0 stars 0 forks source link

On 3 level deep checktree the root elements are undetermined if one node is pre-checked (html_data) #877

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. bild a tree with checkboxes 3 levels deep like this

<div id="tree">
<ul>
 <li id="1" class="jstree-unchecked">
  <a href="">1</a>
  <ul>
   <li id="1.1" class="jstree-unchecked">
    <a href="">1.1</a>
    <ul> 
     <li id="1.1.1" class="jstree-unchecked">
      <a href="">1.1.1</a>
     </li>
    </ul>
   </li>
  </ul>
 </li>
 <li id="2" class="jstree-checked">
  <a href="">2</a>
  <ul>
   <li id="2.2" class="jstree-checked">
    <a href="">2.2</a>
    <ul>
     <li id="2.2.1" class="jstree-checked">
      <a href="">2.2.1</a>
     </li>
    </ul>
   </li>
  </ul>
 </li>
</ul>
</div>
<script type="text/javascript">
$("#tree").jstree({
        "themes" : {
            "theme" : "classic",
            "dots" : true,
            "icons" : false
        },
        "plugins" : [ "themes", "html_data", "checkbox" ]
});
</script>

2. Open the page

What is the expected output? What do you see instead?

I expected to see:
1 (unchecked)
2 (checked)

I get:
1 (undetermined)
2 (undetermined)

What version of the product are you using? On what browser?
jsTree 1.0-rc2, Firefox 3.6.13

Please provide any additional information below.

As soon as I open all nodes he corrects the states, but initially it is 
undetermined

Original issue reported on code.google.com by cysli...@googlemail.com on 1 Feb 2011 at 2:21

GoogleCodeExporter commented 9 years ago
And here is how I fixed this bug:

As far as I understand it, the _repair_state function has the bug.
It is performing the operation to test for parents on all objects at once 
instead of testing each one individually.

Here are my code changes that seem to work:

_repair_state : function (obj) {
    var t = this;
    $(obj).each(function() {
        o = t._get_node(this);
        if(!o.length) { return; }

        var a = o.find("> ul > .jstree-checked").length,
        b = o.find("> ul > .jstree-undetermined").length,
        c = o.find("> ul > li").length;

        if(c === 0) { if(o.hasClass("jstree-undetermined")) { t.check_node(o); } }
        else if(a === 0 && b === 0) { t.uncheck_node(o); }
        else if(a === c) { t.check_node(o); }
        else { 
            o.parentsUntil(".jstree","li").removeClass("jstree-checked jstree-unchecked").addClass("jstree-undetermined");
        }
    });
},

Original comment by cysli...@googlemail.com on 1 Feb 2011 at 3:17