How to leverage Vue Selectize to fetch JSON data from dropdown options?

I have integrated vue2-selectize to showcase a list of options fetched via an axios call:

<template>
    <selectize v-model="selected" :settings="settings">
        <option v-for="option in options" :value="option.id">
            ({{ option.author }}) - {{ option.description }}
        </option>
    </selectize>
</template>

<script>
    export default {
        props: ['old-value'],

        data() {
            return {
                selected: this.oldValue,
                options: [],
                settings: {
                    preload: true,
                    placeholder: "Search All Authors",
                    dropdownParent: 'body',
                    closeOnSelect: true,

                    render: {
                        option: function (data) {
                            console.log(data);
                            return '<div>' +
                                data.displayName +
                                '<div class="item-bio">' +
                                data.bio +
                                '</div>';
                        }
                    },

                    load: async (query, callback) => {
                        axios.get(route('api.showAllAuthors')).then(response => {
                            this.options = response.data;
                            callback();
                        })
                    }
                },
            }
        },
    }
</script>

The challenge I am encountering is that once the <option> for the select element is configured, I can only manipulate the two values it passes to the render function (text and value) and not the original object itself (which the actual <option> accesses).

The documentation mentions the optional parameter of dataAttr for <option> tags, but even after setting

<option :data-data="option">
, I am unable to access the original properties.

Is there a way to retrieve the original JSON attributes utilized by the <option> in the render function?

Answer №1

let selectedValue = mySelectObject.value,
    optionData = mySelectObject.options[selectedValue];

mySelectObject represents the object associated with a specific select or input field. To access it using jQuery:

let mySelectObject = $('#example-select')[0].selectize;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The installation of vue-cli failed due to permission issues with error code EPERM in npm

I keep encountering an error message when I try to run npm install -g vue-cli: npm ERR! path C:\Users\End User\AppData\Roaming\npm\node_modules\vue-cli\node_modules\nan\package.json npm ERR! code EPERM ...

Utilizing Vue.js to fetch information from a post API in Node.js

I'm currently working on developing a post API in Node.js, with Vue.js as my frontend framework and using vue-resource to interact with APIs. Here is the submit function I have implemented on the frontend: validateBeforeSubmit() { var self = this ...

Upon executing npm install in my Laravel project, an error message promptly appears stating: "npm WARN deprecated [email protected]: gulp-util is deprecated - replace it."

Recently, I set up a brand new Laravel Project. After executing the command: php artisan preset vue, when I tried running npm install, an error occurred that stated: npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, followi ...

Is there a way to send a post request containing a base64 encoded image?

I am currently developing an image upload component in Vue.js that includes a custom cropping option. The cropped version of the image is saved in my state as a base64 string, like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAYAAAB91L6 ...

Encountered a SyntaxError while deploying Nuxt.js SSR on Passenger: The import statement cannot be used outside a module

I am currently in the process of deploying my Nuxt app on a hosting service that uses Passenger to run Node.js applications. After building the app with the command ">npm run build" and deploying the content from the .nuxt folder onto the server, specif ...

Is there a way to differentiate between a browser application running on a local development server and an online staging server?

Is there a way to conditionally call a component only on the staging server and not on the local machine in Vue.js? <save-drafts-timer v-if="!environment === 'development'" /> ... data () { return { environment ...

Leveraging Javascript Modules within a Typescript Vue Application

The issue at hand I've encountered a problem while attempting to integrate https://github.com/moonwave99/fretboard.js into my Vue project. My initial approach involved importing the module into a component as shown below: <template> <div&g ...

What are the steps to crawl and save content from multiple websites simultaneously?

My project involves creating a webpage that can crawl multiple other webpages and integrate the data. I am using node.js & vue.js for this purpose. By utilizing puppeteer & cheerio, I have successfully been able to crawl a single page and store its data i ...

Utilizing Nicknames in a JavaScript Function

I'm dealing with a function that is responsible for constructing URLs using relative paths like ../../assets/images/content/recipe/. My goal is to replace the ../../assets/images section with a Vite alias, but I'm facing some challenges. Let me ...

Guide to resolving a blank webpage issue post running 'npm run build'

I am currently in the process of working on a project that involves Vue and Firebase. Unfortunately, I have encountered an issue where my development server is no longer rendering new routes from my Vue router after building and deploying to production. F ...

Is there a Nuxt/Vue glitch causing the server to be called multiple times on a single route or page?

Why is Nuxt making multiple server calls on a single route/page? I tested the example from their express-template: import express from 'express' import { Nuxt, Builder } from 'nuxt' import api from './api' const app = expr ...

Utilizing Vue.js to connect with a Node.js server

After setting up a basic Node.js server, the following code is running successfully: var http = require('http'); var server = http.createServer(); server.on('request', function(req, res) { res.writeHead(200, { 'content ...

Leveraging Environment Variables in Vue.js

I've been diving into the official documentation, but haven't come across any information regarding environment variables. While there are community projects that offer support for this feature, they seem a bit excessive for my needs. I'm cu ...

Why does Request-Body(req.body) display a value while Request-QueryParams(req.queryParams) returns null?

Using vuejs-axios, I successfully transferred client-side data to the server-side using Java with SparkJAVA Framework to manage the request-response cycle. The following code snippets demonstrate how Form-Data is posted from vuejs to java. const formData ...

In what ways can I align the ESLint rules of my Node.js server with those of my Vue.js frontend?

I am looking to ensure that my Node.js server-side files follow the same ESLint rules as my Vue.js frontend. The .eslintrc.js file in my Vue project is structured as follows: module.exports = { root: true, env: { node: true }, extends: ["plugin ...

Converting a string into an array of JSON objects

I am currently attempting to send data to my NodeJS server using the HTTP protocol (vue-resource). The goal is to send an array of JSON objects structured like this : [{"name":"Charlotte","surname":"Chacha","birth":"2000-04-02"},{"name":"Michael","surname ...

Encountering a problem while running npm build (PostCSS plugin postcss-purgecss needs PostCSS 8) on vuejs3 with tailwind

I'm currently in the process of developing an application using Vue.js 3 and Tailwind CSS. While testing some configurations before diving into the project, I encountered a specific error message when running npm run build: ERROR Failed to compile wit ...

The functionality of Highcharts-more.js is not functioning properly within a project set up using vue-cli

Recently, I have been working on a vue-cli project and attempting to create a polar chart similar to the one shown here: To achieve this, I needed to install and import the highcharts and highchart-more libraries using npm. However, upon importing both fi ...

Node.js vulnerability labeled as CVE-2021-38628

Description: Enhance security measures by disabling the use of TLSv1.0 protocol and transitioning to a more secure option like TLSv1.2. To perform a manual test, utilize the following openssl commands: openssl s_client -connect ip:port -tls1. If succes ...

Where can Vue.js be found?

After dedicating an hour to watching instructional YouTube videos on Vue.js, I am still struggling to grasp the language! In the past, I have worked with Node.js, Jquery, and Mongodb to develop websites... I believe that web applications require multiple ...