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

    q-tree: Is there a getParentNode() method?

    Help
    2
    4
    581
    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.
    • M
      murrah last edited by

      Each node in my tree has a unique nodeid property and node-key="nodeid".

      With a set of ticked nodes, I also need to get their parents. getNodeByKey() and getTickedNodes() return node objects but it seems I cannot do:

      const aNode = this.$refs.myTree.getNodeByKey(nodeid)
      const parentNode = aNode.getParent()
      

      Instead I have made my own method:

          getParentNode (nodeid) {
            const nodeMeta = this.$refs.myTree.meta[nodeid]
            const parentNode = this.$refs.myTree.getNodeByKey(nodeMeta.parent.key)
            return parentNode
          }
      

      Am I missing something or is that the way to do it?
      Thanks,
      Murray

      M 1 Reply Last reply Reply Quote 0
      • M
        murrah @murrah last edited by

        A more robust version:

            getParentNode (nodeid) {
              let parentNode = null
              if (nodeid) {
                const nodeMeta = this.$refs.projectTree.meta[nodeid]
                if (nodeMeta.parent) {
                  parentNode = this.$refs.projectTree.getNodeByKey(nodeMeta.parent.key)
                }
              }
              return parentNode
            }
        
        metalsadman 1 Reply Last reply Reply Quote 0
        • metalsadman
          metalsadman @murrah last edited by metalsadman

          @murrah I use a recursive function for this, my node structure is unlimited nesting. i use scope-slots ie.

          // node model
          [{
            id: 1, // unique id
            name: '',
            description: '',
            children: [], // same array of objects like this node
            parent_id: null, // null indicates this node is root, else holds id of its immediate parent
            ... // other props
          }]
          
          getRootNode (tree, node) {
                let curNode = node.parent_id !== null ? tree.getNodeByKey(node.parent_id) : node
                if (curNode.parent_id !== null) {
                  curNode = this.getRootNode(tree, curNode)
                }
                return curNode
              }
          
          M 1 Reply Last reply Reply Quote 0
          • M
            murrah @metalsadman last edited by

            @metalsadman Thanks! 🙂

            1 Reply Last reply Reply Quote 0
            • First post
              Last post