Exploring the functionality of Vue.js Multiselect with data

After making a Mounted axios call, I have received some response data from the server which is quite promising.

Now, I want to extract a specific part of this data to use as an option in a multiselect :options.

Here is what my Vue component looks like:

// ===Component name
name: "create_order",
// ===Props passed to component
props: {},
// ===Components used by this component
components: {
    Datepicker,
    Multiselect,
},
// ====component Data properties
data(){
    return{
        formcreateorder: {},

        dateoforder: "",
        format: 'dd MMMM yyyy',

        orderconsultant: null,
        orderconsultantoptions: ['Mr', 'Mrs', 'Miss', 'Ms'],

        ordertype: null,
        ordertypeoptions: ['Temp', 'Perm'],

        orderclient: null,
        orderclientoptions: []

    }
},
// ===Code to be executed when Component is mounted
mounted() {
    // Make a ajax request to get data from jobs route
    axios.get('clients/get').then(response => this.orderclientoptions = response.data);
},
// ===Computed properties for the component
computed: {},
// ===Component methods
methods: {
}

Here is how my front end looks:

<multiselect v-model="orderclient" id="orderclient" name="orderclient" :options="orderclientoptions"></multiselect>

And here is the response I received:

{id: 1, clientname: "Tech Dojo", industry: "Tech", consultant: "Bob", clientstatus: "Lapsed",…}

My goal is to use the "clientname" in the response as my multiselect option.

I have tried a few approaches but haven't been successful. I'm hoping for some guidance on how to achieve this.

Answer №1

When focusing solely on the client's name, you can transform the response into a string array containing only the client names. This assumes that the response you receive is an array of clients.

mounted() {
    axios.get('clients/get')
         .then(response => 
               this.orderclientoptions = response.data.map(x => x.clientName);
}

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 JavaScript code is producing a numerical output instead of the intended array

I am facing an issue with my program that is designed to eliminate items from a list of arguments. function destroyer(arr) { var args = [].slice.call(arr); var data = args.shift(); for(var i = 0; i < args.length; i++){ var j = 0; while(j ...

Loading a Float32Array into Node v8 using C++

After thoroughly reviewing the documentation: Float32Array ArrayBuffer Array I am attempting to fill a v8 array with floats by utilizing a thrust::host_vectofr<float>, where dataset[i].vector = thrust::host_vector<float> When using an Array ...

The concept of setting a value is not defined in JavaScript when compared to

Within my primary python script, the following code snippet is present. @app.route('/accounts/test/learn/medium') def medium(): word = random.choice(os.listdir("characters/")) return render_template('accounts/test/medium.html', word=w ...

Having trouble getting the Keycloak provider to work with Next-Auth?

It's puzzling to me why my next-auth integration with Keycloak server is failing while the integration with Github is successful. import NextAuth from "next-auth" import KeycloakProvider from "next-auth/providers/keycloak"; import ...

Vue.js - default radio button selection not working

Vue documentation mentions that if the initial value of v-model does not match the radio values, it will appear as unselected. Despite following all the steps correctly, the Public radio button is not checked by default. Radio Component: <template> ...

Obtain the index of the selected item from a dropdown menu

Is there a way for the selectedIndex to return -1 if no item is selected, instead of the element's text at position 0? It seems that the selectedIndex always returns 0 even when nothing is selected. <select id="abc" name="abc"> <option& ...

To use Material-UI Tooltip, the child title prop must be removed

I am facing an issue while trying to implement the Material-UI Tooltip component on a component that already has the title property. I need to use the child with the title prop, but I'm unsure if it's possible to combine both or if I should look ...

An easy way to attach a Contextmenu to a specific element

I have implemented a scrolling feature for one of the div elements in my Application. Inside this div, there is a templated table with over 100 rows. Users are able to add or delete rows using a contextMenu. The contextMenu offers 4 options - AddTop, AddB ...

Jasmine Timeout issue

Currently, I am in the process of writing a karma unit test script. Everything seems to be going smoothly, but unfortunately, I am encountering an error: Chrome 39.0.2171 (Windows 7) Unit: common.services.PartialUpdater Should be loaded with all dependenc ...

What is the best way to loop through an object while keeping track of its value types

I have a JSON file containing UI adjustments sourced from the API: interface UIAdjustmentsJSON { logoSize: number; themeColor: string; isFullScreen: boolean; } To simplify things, let's utilize a static object: const adjustments: UIAdjust ...

Combining Two JSON Arrays Featuring Unique Keys

I have two JSON arrays with slightly different keys. The first JSON array contains the keys id, name, and title. The second JSON array includes id, title, forename, name, and company. I am wondering if it's possible to merge these two arrays so th ...

Refreshing jQuery via Ajax Response

In our JSF2 application, we encounter situations where we need to re-invoke the JavaScript (specifically jQuery for UI styling) when making Ajax calls. However, it seems that the JavaScript functions are not being called upon receiving the Ajax response fr ...

A method for calculating the average of values with identical keys within an object contained in an array

I have a JSON object that contains countries and data values. I need to add up the values of each country and compute their average. Here is the JSON object: var arraySeries = [{"country":"United States","data":2}, {"country":"Venezuela ...

A guide on combining two native Record types in TypeScript

Is it possible to combine two predefined Record types in TypeScript? Consider the two Records below: var dictionary1 : Record<string, string []> ={ 'fruits' : ['apple','banana', 'cherry'], 'vegeta ...

Running JavaScript within Electron is a straightforward process

Looking to create an Electron application that can take code entered into a text area, execute it, and display the result. Any advice on converting the text to JavaScript and running it? ...

What is the most efficient way to transfer substantial data from a route to a view in Node.js when using the render method

Currently, I have a routing system set up in my application. Whenever a user navigates to site.com/page, the route triggers a call to an SQL database to retrieve data which is then parsed and returned as JSON. The retrieved data is then passed to the view ...

Displaying a div when a button is clicked (PHP)

Hello everyone, I'm new to posting here so please bear with me if I seem inexperienced. On my website, there is a button that needs to disappear when clicked and be replaced by a form without refreshing the page. I was able to accomplish this using ...

Incorporate a vertical scrollbar in the tbody while keeping the thead fixed for smooth vertical scrolling

I'm seeking a solution to implement horizontal and vertical scroll for my table. Currently, the horizontal scroll is working fine, but when trying to add vertical scroll, the table header also moves along with it. Is there a way to keep the table hea ...

Tips for creating line breaks in Google Chart tooltips

I'm having trouble breaking a line in the code snippet below. Here is the complete code: <html> <head> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script ...

Exploring the differences between utilizing Node JS Express for server-side development and displaying console output to

Recently, I started delving into the world of node js and came across IBM's speech to text sample application (https://github.com/watson-developer-cloud/speech-to-text-nodejs). This app utilizes the express framework and showcases transcribed audio fr ...