我想从多选字段中选择一个选项并更新所选对象的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>
此代码为每个选定的选项创建输入,但整个选项文本作为值存储在输入中。它也不会更新对象的属性。
答案 0 :(得分:2)
目前我更喜欢“观看”:
watch: {
multiselect: function(indexes) {
for(var i = 0; i < this.options.length; i++)
this.options[i].show = indexes.indexOf(i) > -1;
}
}
完整示例:
答案 1 :(得分:1)
要更新选择对象的值,我已经在for循环中重新启动了Item并将输入模型绑定到items值:
return Shim.provider
.request(endPoint)
.timeout(7,
scheduler: MainScheduler.asyncInstance)
.retry(3)
.flatMap { result: ImmutableMappable -> Observable<Response> in
return Observable.create{
switch result {
case .authorize:
observer.onNext(AuthorizeResponse())
case .deAuthorize:
//etc
case step:
//etc.
}
}
}
答案 2 :(得分:0)
只需使用类似的东西
<Multiselect :options="Options" :value="Values" :multiple="true" @update="updateMultiValue"> </Multiselect>