question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get selected Node data

See original GitHub issue

Hi!

Thanks for your wonderfull library.

I see in src/lib/Node.js that events are emitted when a node is selected. How would I listen to that event to dynamically display the nodes data object into a Div?

If selectedNodeInfo() is run every time a node gets selected then this would work :

<template>
  <div>
    <LiquorTree :data="dirTree" :options="treeOptions" ref="tree"/>
    <div >{{selected}}</div>
  </div>
</template>

<script>
  import LiquorTree from 'liquor-tree'
  import axios from 'axios'
  export default {
    name: "resourceTree",
    components: {
      LiquorTree
    },
    data() {
      return {
        dirTree: this.getDirPaths(),

        // This property should contain the selected node's Object.
        selected : {},
        treeOptions: {
          propertyNames: {
            text: 'name',
            children: 'children'
          }
        }
      }
    },
    created() {
        this.getDirPaths()
    },
    methods : {
      getDirPaths() {
        return axios.get("http://localhost:9090/fragpaths")
          .then(response => response.data)
      }
    },
    selectedNodeInfo() {
    this.selected = this.$refs.tree.findAll({state: { selected: true } })
    }
  }
</script>

<style scoped>

</style>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amsikcommented, Mar 23, 2018

Hi! Thank for using the library 😃

I had some thought about v-model and checkboxes. You can update library and check it out or CDN (https://cdn.jsdelivr.net/npm/liquor-tree@0.2.15/dist/liquor-tree.umd.js) Also I’ve added examples (npm run dev and open Checkboxes page).

For your example:

<div id="app">
  <pre v-if="treeModel && treeModel.selected">
    {{ treeModel.selected.map(el => el.text) }}
    </pre>
  <pre v-if="treeModel">
    {{ treeModel.checked.map(el => el.text) }}
    </pre>
    <tree
      ref="tree"
      :data="treeData"
      :options="treeOptions"
      v-model="treeModel"
    />
  </div>
<script>
    new Vue({
      el: '#app',
      data: function() {
        return {
          treeModel:  null,
          treeData: [
            { text: 'Item 1', state: { checked: false } },
            { text: 'Item 2', state: { checked: true }, children: [
            	{ text: 'Item 2.1', state: { checked: true } },
                { text: 'Item 2.2', state: { checked: true } },
                { text: 'Item 2.3', state: { checked: false } }
            ]},
            { text: 'Item 3', state: { checked: true } },
            { text: 'Item 4', state: { checked: true } }
          ],
          treeOptions: {
          	checkbox: true,
          }
        }
      }
    })
</script>
0reactions
abhioncommented, Oct 22, 2020

How do I get indeterminate nodes too?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get the selected Node from a jstree - javascript - Stack Overflow
var data = $(yourtree).jstree().get_selected(true)[0].text;
Read more >
How to retrive get_selected('full',true) attribute value
if i want to get only the selected node "id" i do: var selected = $('#tree').jstree(true).get_selected();. Now, I've tryed to use the 'full'...
Read more >
Get Selected Node Data In Selected Order - GoJS
If you want a different order, I think you'll need to copy the collection to your own Array or List and sort it...
Read more >
ASPxTreeList - How to get the values from a selected node on ...
I am trying to implement the TreeList and I need to be able to select a specific node and get the values (or...
Read more >
TreeView.SelectedNode Property (System.Web.UI.WebControls)
The following code example demonstrates how to use the SelectedNode property to determine the value of the selected node in the TreeView control....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found