javascript - 从vue js中的多选框中检索选定的值

标签 javascript vue.js

我很难从 Vue 中的多选框中检索值。用户选择任意数量的值后,我想检索这些值并提交到数据源。到目前为止还没有运气。下面是我的代码的摘录。

<div id="app">
   <select multiple v-bind:data-id="program.id" :disabled="!program.editable" v-model="program.dropDowns">
       <option>Microsoft</option>
       <option>IBM</option>
       <option>Google</option>
       <option>Apple</option>
   </select>
</div>
getPrograms: function() {
      axios.get("https://my-json-server.typicode.com/isogunro/jsondb/Programs").then((response) => {
          this.programs = response.data.map(row => ({
            ...row,
            dateFormatted: toDDMMYY(row.Date),
            editable: false,
            dropDowns: ["Apple","Google"]
          }));
        console.log(this.programs)
        })
        .catch(function(error) {
          console.log(error);
        });
}

任何帮助将不胜感激。这是实际的pen

最佳答案

只是你错误地分配了下拉数据,需要如下更改:

模板略有变化:

<button v-else  @click="saveItem(program)">save</button>

和 saveItem() 方法如下:

saveItem (program) {
     program.isReadOnly = true
     program.editable = false
     console.log(program)
     alert(program.dropDowns)
    }

关于javascript - 从vue js中的多选框中检索选定的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58966599/

相关文章:

JavaScript - 编写嵌套函数的方法

javascript - 我的输入字符串值不会显示在我的列表中

vue.js - Vue - 深入观察对象数组的变化,无论是添加对象还是修改对象

javascript - 自定义输入组件忽略来自方法的更新

javascript - 仅当元素存在时才使用 Jquery 函数(Ajax 调用)

javascript - gruntjs:使用多个任务多次修改文件的策略

javascript - 为什么我们要在没有依赖数组的情况下使用 useEffect?

javascript - Vue.js v-if 用于属性

javascript - 如何在 VueJs 中将值从函数传递到变量?

javascript - 为什么 Vue.js 使用 VDOM?