Raphaël Gabriel
Raphaël Gabriel

Reputation: 83

Vuejs - Change selected options in select from outside

How do I change selected options from the outside?

I have a multiple select and the user can click on the "All" button to select all the options.

Fiddle.

I've tried to use the jQuery function "prop", but it only works visually; it doesn't change the Vue data.

$('option', '#filter-accountexpl').prop('selected', true);

Upvotes: 0

Views: 632

Answers (1)

Bert
Bert

Reputation: 82459

Stop using jQuery to do this.

You can select all of your options this way.

this.vaccountsexpl = Object.keys(this.accountsexpl)

You can select none of your options this way.

this.vaccountsexpl = []

You can select any list of your options this way.

this.vaccountsexpl = [129,132,133]

Here is your fiddle updated.

Vue is driven by data.

Upvotes: 1

Related Questions