treejs icon indicating copy to clipboard operation
treejs copied to clipboard

`checked: true` boolean inversion issue

Open ForbiddenEra opened this issue 1 year ago • 1 comments

Hi,

If your tree array is as such:

let data = [
  {
    "id": "0",
    "text": "0",
    "checked": true,
    "children": [
      {
        "id": "0-0",
        "text": "0-0",
	"checked": true,
        "children": []
      }
    ]
  }
]

Then no nodes are selected. This is because the checked must be implemented as a toggle of sorts, inverting the previous value, so because the parent is checked, setting checked: true on a child causes the parent to be inverted, unchecking it and seemingly also unchecking the child.

This doesn't make intuitive sense and it took me a good few minutes to figure out what was going on in this case.

Because of this, you either need to set checked: true on the most-parent node that you want all children checked in, or, if you don't want all that parent's children checked, then you need to not have the property on the parent and only on the child nodes you want checked.

checked: true should mean I want that entry checked, regardless of any previous values; there should be no inversion toggling.

ForbiddenEra avatar Mar 20 '24 06:03 ForbiddenEra

I had the same problem. I was able to resolve it by directly calling the setValues function from loaded when creating the Tree structure. Additionally, I set the status to 2 during creation. This method fixed the toggle issue of checked.

AR0101 avatar Jun 25 '24 05:06 AR0101