# treeList widget ... dynamically check (parent) items

**URL:** <https://discourse.nodered.org/t/treelist-widget-dynamically-check-parent-items/27737>\
**Category:** Developing Nodes\
**Created:** [3 June 2020 22:48 UTC](https://discourse.nodered.org/t/treelist-widget-dynamically-check-parent-items/27737 "2020-06-03T22:48:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [3 June 2020 22:48 UTC](https://discourse.nodered.org/t/treelist-widget-dynamically-check-parent-items/27737/1 "2020-06-03T22:48:06Z")

</div>

Hello,

I have a small question regarding the tree list widget.  
I have a list with child items. If a child is checked I like that the parents are checked dynamically.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/62501e62c56153e05edc48accae9d408156de148.png)

I have done a event function which changes the data but this don`t refesh the tree conetent:

```auto
  var extensionsTreeCheck = function(item) {

    var checkParents = function(parent) {
      parent.selected=true;
      if (parent.hasOwnProperty('parent')) checkParents(parent.parent);
    }

    if (item.hasOwnProperty('parent')) checkParents(item.parent);
  }

```

So my workaround is this. Reading the tree data with `.data()' and writing it back to the widget.

```auto
      .on('treelistselect', function(event, item) {
        if (item.selected) {
            node.extensionsTreeCheck(item);
            extensionData[$('#node-input-exDeviceId').val() || node.exDeviceId] = treeLists[id].treeList('data');
            treeLists[id].treeList('data',extensionData[$('#node-input-exDeviceId').val() || node.exDeviceId]);
        } 
      })

```

_(I have more than one treeList so this is why there is a treelist[id]. And many contexts depending on a select dropdown.)_

This works but it is not the best way (I think) as it clears the treeList and redraws it.

Is there a better solution?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 August 2020 22:56 UTC](https://discourse.nodered.org/t/treelist-widget-dynamically-check-parent-items/27737/2 "2020-08-02T22:56:27Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
