Q-Tree How to tick all nodes



  • Is there a way to tick all nodes in a Q-Tree, either by a directive or programmatically?
    I want all nodes to be initially ticked when I show the component.
    My nodes are dynamically loaded through a computed vue property, so I can’t simply set the ticked.sync prop.



  • You could do it in your computed props setter.



  • This is how I do it:

    <q-tree
        :nodes="nodes"
        :ticked.sync="tickedNodeKeys"
        node-key="key"
       ...
     />
    
    data() {
       return {
          tickedNodeKeys: [],
          allNodeKeys: []
       }
    },
    computed() {
       nodes() {
          // !!! while generating the nodes, I collect the keys and write them into this.allNodeKeys
          // if you want to tick everything initially, you can set this.tickedNodeKeys here right away
          // return generated nodes
       }
    },
    methods: {
       tickAll() {
          this.tickedNodeKeys = [...this.allNodeKeys];
        }
    }
    

    I hope it helps



  • @chyde90 works like a charm, thanks!


Log in to reply