Answer the question
In order to leave comments, you need to log in
Grouping and restricting options in select vue.js?
https://codepen.io/dauren10/pen/REYJye
How can I make it so that in the select of each goal the user can select a maximum of 100?
That is, he chose 20 for the first task, then 40 remain for the second and third. In general, the options for each goal should be no more than 100.
Similarly, for 2 goals, I chose, say, 50 for the fourth task, then the fifth is also 50.
And all the goals in the same way.
Answer the question
In order to leave comments, you need to log in
Put the data on the goals and their constituent tasks into an array:
data: () => ({
goals: [
{
name: '...',
tasks: [
{ name: '...', value: 0 },
{ name: '...', value: 0 },
...
],
},
...
],
}),
methods: {
getValues(tasks, task) {
const max = 100 - tasks.reduce((acc, n) => acc + n.value, -task.value);
return [ 0, 10, 20, 30, 40, 50, 60 ].filter(n => n <= max);
},
},
<tr v-for="g in goals">
<td>{{ g.name }}</td>
<td>
<div v-for="t in g.tasks" class="task">
{{ t.name }}
<select v-model.number="t.value">
<option v-for="v in getValues(g.tasks, t)" :value="v">{{ v }}</option>
</select>
</div>
</td>
</tr>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question