No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Calling <q-tree> component methods

    Help
    q-tree
    2
    2
    1763
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      pavarine last edited by

      Let’s say I have a tree component:

      <template>
      <div>
      <q-tree
      :nodes=“tree_data”
      :selected.sync=“tree_selected_node”
      node-key=“uuid”
      />
      </div>
      </template>

      How can I call a method from the tree component (let’s say the getNodeByKey(key) method) from inside an arbitrary method that is in <script> methods: {…} </script> ? In other words, how can I reference the q-tree element from outside it?

      Thanks

      1 Reply Last reply Reply Quote 1
      • P
        peetc last edited by

        Give the tree component a ref
        <q-tree
        ref=“tree”
        :nodes = “companySetup”
        :selected.sync=“selected”
        …

        Then use it like this:
        methods: {

        nodeExists(key) {
            return this.$refs.tree.getNodeByKey(key)
        },
        getSelectedNode() {
            return this.$refs.tree.getNodeByKey(this.selected)
        },
        1 Reply Last reply Reply Quote 1
        • First post
          Last post