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

    How can I use JSON data to populate the options of a q-select ?

    Help
    2
    3
    330
    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
      thri60 last edited by

      Please anyone which an example on how to use a json to populate a q-select… or inject json objects into q-select… I’m new to quasar…

      I 1 Reply Last reply Reply Quote 0
      • I
        Ilia @thri60 last edited by Ilia

        @thri60 That would depend on where that json is stored. If that is a web link, you can do something like this:

        onLoad (response) {
             console.log(response)
        }
        
        onError (error) {
             console.log(error)
        }
        
        const oReq = new XMLHttpRequest()
        oReq.onload = onLoad
        oReq.onerror = onError
        
        oReq.open('get', 'https://domain.com/data.json', true)
        oReq.send()
        

        if that is inside your project and will be packed:

        import json from '/path-to-json/data.json'
        

        or if you need specific values:

        import { value1, value2 } from '/path-to-json/data.json'
        
        T 1 Reply Last reply Reply Quote 2
        • T
          thri60 @Ilia last edited by thri60

          @ilia this was really helped.

          I just had to

          import  location from '/assets/locations.json
          

          then

          export default {
          data() {
               return {
                        locations: location,
                          }
                   }
             }
          

          then referenced locations

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