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

    QTree selection and ticking id to create dynamic components

    Help
    3
    7
    1161
    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.
    • T
      Todo Digital last edited by

      I am using the QTree component with the selection and ticking option as in this example:

      https://quasar.dev/vue-components/tree#Selection-vs-ticking%2C-expansion

      I see that it uses the label as id. How can I assign a custom ID to each node(label) so I can use <component :is=“dynamicComponent” /> and generate dynamic components based on the options I ticked? The label has spaces, and of course it will give me errores if I use the label as the :is prop to generate the dynamic components. Any ideas on this?

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by

        You can have both a nodeKey and a label. The example you linked to is only using the label as the node-key. You can add a nodeKey property to your data and use that as the node-key.

        https://codepen.io/smolinari/pen/GaLgYm

        Scott

        T 1 Reply Last reply Reply Quote 0
        • T
          Todo Digital @s.molinari last edited by

          @s-molinari Hi. Thank you for your response. I have been studying the tree component, and I noticed that the ticked data is a simple array, that will then will sync with the node-key to show the ticked options. After that, you will need to do a v-for for the ticked array, and I will only be able to access the simple value in the array. I was wondering, if there is a way for the ticked array to be an object, so I can access the label and my custom key (that I am using as a component name for dynamic use) inside the v-for. It will help me to use the label as a title and key as dynamic component name. I am not sure if I am clear enough. I was able to do exactly the codepen example, but instead of key I named it id. So basically, just wondering if ticked can be an object { id: “componentName”, label: “Component Name”} and I can use both values inside the v-for loop.

          1 Reply Last reply Reply Quote 0
          • T
            Todo Digital last edited by

            To be able to use the label as component name I had to create a filter that will delete the white spaced, and then call the dynamic component like this:

            <h2>{{ tick }}</h2>
            <component :is=“tick | removeWhiteSpace” ></component>

            What I was looking for is to use an object with the ticked data like this:

            <h2>{{ tick.label }}</h2>
            <component :is=“tick.component” ></component>

            1 Reply Last reply Reply Quote 0
            • s.molinari
              s.molinari last edited by

              But, if you have the key/ id, you can “query” for and return any data you need out of the tree.

              https://codepen.io/smolinari/pen/GaLgYm

              Scott

              T 1 Reply Last reply Reply Quote 1
              • T
                Todo Digital @s.molinari last edited by

                @s-molinari thank you again for our time. Thought of that, about query the object with the key and return the desired data. It is just that I thought I was missing something from the QTree component, but now that I see your code and tested myself, works great. This really gives QTree a huge potencial.

                Regards,
                Jaime

                1 Reply Last reply Reply Quote 0
                • Q
                  QuaSam last edited by

                  You guys could have saved me a lot of time earlier today! Really glad to have found this thread, and the most helpful example by s.molinari with CodePen implementation (which includes the settings for Quasar). Thanks a bunch - I feel like you’ve more than made up my wasted time today.

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