【发布时间】:2018-11-07 12:07:52
【问题描述】:
我有以下带有 2 个选择和 2 个按钮的 HTML,用于在选择之间传输选项:
<div class="col-xs-1" style="width:45%">
<label for="txtDescricao">Motivos</label>
<select multiple="multiple" class="form-control" id="todosMotivos" v-model="Motivos_selected" style="width: 100%;">
<option v-for="motivo in Motivos" v-bind:value="motivo.Codigo">{{motivo.Descricao}}</option>
</select>
</div>
<div class="col-xs-1 text-center align-middle" style="width:10%">
<br />
<p><button type="button" class="btn btn-default btn-sm fa fa-arrow-right" v-on:click.prevent="adicionarItensSelect"></button></p>
<p><button type="button" class="btn btn-default btn-sm fa fa-arrow-left" v-on:click.prevent="removerItensSelect"></button></p>
</div>
<div class="col-xs-1" style="width:45%">
<label for="txtDescricao">Motivos vinculados</label>
<select multiple="multiple" class="form-control" id="selectedMotivos" v-model="Motivos_vinculados_selected" style="width: 100%;">
<option v-for="motivo in Motivos_vinculados" v-bind:value="motivo.Codigo">{{motivo.Descricao}}</option>
</select>
</div>
这里是 vue 应用数据:
Motivos: [],
Motivos_selected: [],
Motivos_vinculados: [],
Motivos_vinculados_selected: [],
“Motivos”列表正在以这种方式加载:
getMotivos: function (motivosVinculados) {
var self = this;
$.ajax({
type: "POST",
url: "../Motivo/GetMotivos",
success: function (data) {
self.Motivos = data.motivos;
},
error: function (error) {
console.log(error);
alert('Erro ao executar operação.');
}
});
},
我正在尝试将选定的选项转移到第二个这样选择:
adicionarItensSelect: function () {
var self = this;
self.Motivos_vinculados.push(self.Motivos_selected);
},
但是,相反,第二个 Select 选项变为空白:
我认为该项目不会将第二个 Select 作为同一个对象。我该怎么做才能解决这个问题?
【问题讨论】:
-
嗨@Taian 你能在 jfiddle 上复制这个问题吗?
-
嗨@MazinoSUkah!关注 jsfiddle:jsfiddle.net/kopq6x2f
-
请检查我的回答,看看是否有帮助
标签: javascript vue.js