How can I get current node and pass it as request parameter to display it child nodes using Quasar Tree lazy loading?



  • I am using Quasar Tree lazy loading to display the data like shown in image

    scn.png

    onclick of first node I am displaying child nodes from a local JSON file, now when i click on respective child node I want to display it sub childs from another JSON file by passing its parent node id.
    Here is my code

    <template>
      <q-page class="flex fixed-left">
        <q-tree
          :nodes="treeArr"
          node-key="id"
          label-key="content"
          ref="tree"
          no-connectors
          :selected.sync="selected"
          text-color="blue"
        >
        </q-tree>
       
    
      </q-page>
    </template>
    <style >
    </style>
    <script>
    
    
    
    import someJson from "./static/somejson.json";
    import datasetsJson from "./static/datasetsjson.json";
    
    
    export default {
      name: "HelloWorld",
      data() {
        return {
          tree: [],
          selected: "",
          selectedObject: null,
          json: someJson,
          djson: datasetsJson,
          newObj: [],
          treeArr: [
            {
              content: "Resources",
              children: [],
            },
          ],
        };
      },
      computed: {},
      methods: {},
        
      created() {
        this.tree = this.get_leaves()
        console.log("json", someJson);
    
       Object.keys(this.json.body.projects.projects).forEach((j) => {
    
         
     var child = { id: j, content: this.json.body.projects.projects[j].friendlyName, children: [] };
     this.treeArr[0].children.push(child);
    console.log("test", this.json.body.projects.projects[j]);
    console.log("childs", child);
    })
    
        
      },
    };
    </script>
    

    Can any one please tell me how can I get current node and pass it as request parameter to display its respective child nodes.



  • @user123 check the events and methods section of the qtree api. selected for example emits the key, use a ref on your qtree then use one of the method getNodeByKey to get the node object.


Log in to reply