Вы можете просмотреть selectedColors1
и получить index
каждого выбранного элемента.Затем переместите их в массив color2
и удалите их из массива colors
по одному.
Демо : CodeSandbox
export class App {
colors1 = [
{ id: "purple", name: "Purple" },
{ id: "black", name: "Black" },
{ id: "orange", name: "Orange" }
];
colors2 = [
{ id: "white", name: "White" },
{ id: "red", name: "Red" },
{ id: "blue", name: "Blue" }
];
selectedColors1 = [];
selectedColors2 = [];
add() {
this.selectedColors1.forEach(selected => {
// get the index of selected item
const index = this.colors1.findIndex(c => c.id === selected);
this.colors2.push(this.colors1[index]); // add the object to colors2
this.colors1.splice(index, 1); // remove from colors1
});
}
}
HTML:
<select multiple value.bind="selectedColors1">
<option repeat.for="color of colors1" model.bind="color.id">
${color.name}
</option>
</select>
<button type="button" click.delegate="add()">Add</button> <br />
<select multiple value.bind="selectedColors2">
<option repeat.for="color of colors2" model.bind="color.id">
${color.name}
</option>
</select>