Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
  Forked from:
  https://quasar.dev/vue-components/tree#Example--Syncing-node-properties
-->
<!-- tick-stratgy: "strict", "leaf", "leaf-filtererd", "none" -->
<!-- See https://quasar.dev/vue-components/tree#Selection-vs-ticking%2C-expansion -->
<!-- "leaf":   Ticks the ticked nodes and all of their children  -->
<!-- "strict": Ticks only the ticked nodes -->
<!-- "none":   Disables ticking -->
<div id="q-app">
  <div class="q-pa-md row q-col-gutter-sm">
      <q-tree class="col-12 col-sm-6"
        ref=myTree
        :nodes="nodes"
        node-key="key"
        tick-strategy="leaf"
        :ticked.sync="ticked"
        :expanded.sync="expanded"
        :selected.sync="selected"
        @update:selected="getNode"
      ></q-tree>
      <div class="col-12 col-sm-6 q-gutter-sm">
        </q-btn>
        <div class="text-h6">Nested array of nodes:</div>
        <div>
          {{ nodes }}
        </div>
        <div class="text-h6">Key of selected node:</div>
        <div>
          {{ selected }}
        </div>
        <div class="text-h6">Object with field of selected node:</div>
        <div>
          {{ selectedObject }}
        </div>
        <div class="text-h6">Array of keys of expanded nodes:</div>
        <div>
          {{ expanded }}
        </div>
        <div class="text-h6">Array of keys of ticked nodes:</div>
        <div>
          {{ ticked }}
        </div>
      </div>
    </div>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                function search (key, parent) {
  // Searches recursively for node with key in q-tree
  // If found, returns field node.mySpecialData
  // Uses a stack to traverse the whole tree until node with key is found
  const stack = []
  let node, ii
  stack.push(parent)

  while (stack.length > 0) {
    node = stack.pop()
    if (node.key == key) {
      return [node.mySpecialData] // return whatever you want here!!!
      // Note: "[]" returns an object with the field, not the field
    } else if (node.children && node.children.length) {
      for (ii = 0; ii < node.children.length; ii += 1) {
        stack.push(node.children[ii])
      }
    }
  }
  return null
}

new Vue({
  el: '#q-app',

  data () {
    return {
      nodes: [
        {
          key: "1",
          label: 'Satisfied customers',
          mySpecialData: 'haloooo',
          children: [
            {
              key: "1.1",
              label: 'Good food',
              mySpecialData: 'yup',
              children: [
                { 
                  key: "1.11",
                  selectable: true,
                  mySpecialData: 'hihihihi',
                  label: 'Quality ingredients' 
                },
                { 
                  key: "1.12",
                  mySpecialData: 'yipee',
                  label: 'Good recipe' }
              ]
            },
            { 
              key: "1.2", 
              label: 'Good service',
              mySpecialData: 'yup-again',
              children: [
                { 
                  key: "1.21",
                  mySpecialData: 'tallyho',
                  label: 'Prompt attention' 
                },
                { 
                  key: "1.22",
                  mySpecialData: 'damnImGood!!!',
                  label: 'Professional waiter' }
              ]
            },
            {
              key: "1.3",
              label: 'Pleasant surroundings',
              mySpecialData: 'baz',
              children: [
                { 
                  key: "1.31",
                  mySpecialData: 'geez', 
                  label: 'Happy atmosphere' 
                },
                { 
                  key: "1.32",
                  mySpecialData: 'foo',
                  label: 'Good table presentation' 
                },
                { 
                  key: "1.33",
                  mySpecialData: 'bar',
                  label: 'Pleasing decor' 
                }
              ]
            }
          ]
        }
      ],
      selected: '',
      ticked: [],
      tickedFromEvent: [],
      expanded: [ "1" ],
      selectedObject: null,
    }
  },
  methods: {
    getNode (selected) {
      console.log("In method getNode");
      // Sample code to access the props of the component, using Vue $refs and $props:
      // Using default syntax:
      // console.log("All props of myTree (object):", this.$refs['myTree'].$props);
      // Using alternative syntax:
      console.log("All props of myTree (object):", this.$refs.myTree.$props);
       // Note that sample prop tick-strategy is named tickStrategy within q-tree props:
      console.log("Prop tick-strategy in props of myTree: ",                  
                   this.$refs.myTree.$props.tickStrategy);   
      // Extract a field of the selected node through above recursive function search:
      console.log("Doing recursive search on selected node");
      this.selectedObject = search(selected, this.nodes[0]);
      console.log("Found object mySpecialData in selected node: ", this.selectedObject)
    },
  },
  })
              
            
!
999px

Console