我想从多个选择字段中选择一个选项并更新选定对象的prozent值:

<div id="assistenzen">
<form>
    <select v-model="assistenz" multiple>
      <option v-for="option in options" v-bind:value="option">
        {{ option.text }}
      </option>
    </select>
    <ul>
        <li v-for="(assi, prozent) in assistenz">{{assi.text}}
            <input v-model="assistenz" v-bind:value="prozent">
            {{assi.prozent}}
        </li>

    </ul>
</form>
</div>


<script>

var assistenz = new Vue({
  el: '#assistenzen',
  data: {
    assistenz: 'keine Assistenz',
    options: [
      { text: 'One', value: 'A', prozent: '0' },
      { text: 'Two', value: 'B', prozent: '0' },
      { text: 'Three', value: 'C', prozent: '0' }
    ]
  },
});
assistenz.config.devtools = true
</script>

此代码为每个选定的选项创建一个输入,但整个选项文本作为值存储在输入中。它也不会更新对象的属性。

最佳答案

目前我更喜欢看:

watch: {
  multiselect: function(indexes) {
    for(var i = 0; i < this.options.length; i++)
      this.options[i].show = indexes.indexOf(i) > -1;
    }
}

完整示例:
https://jsfiddle.net/4xq3mj9o/

关于javascript - 更新Vue中选定对象的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41061895/

10-12 22:55