gpt4 book ai didi

vue.js - vue multiselect 1.1.4,通过id选择值

转载 作者:搜寻专家 更新时间:2023-10-30 22:39:12 25 4
gpt4 key购买 nike

我添加了看起来像这样的多选组件

查看

<multiselect
:options="books"
:selected="selectedBook"
:show-labels="false"
placeholder="Choose your book"
label="name">
<span slot="noResult">No books were found</span>
</multiselect>

脚本

<script>
export default {
data() {
return {
books: [],
selectedBook: null,
}
},
created() {
this.getBooks();
this.getFav();
},
methods: {
getBooks() {
this.$http
.get('/books/')
.then(
function(response) {
this.books = response.json();
}
);
},
getFav() {
this.$http
.get('/fav/')
.then(
function(response) {
var fav = response.json();
this.selectedBook = fav.id;
}
);
}
}
}
</script>

响应

[{"id":1,"name":"ABC"},{"id":2,"name":"QWE"}]

我的问题是,如何通过 id 设置选定的书。当我这样设置时,然后在输入中显示 id,但我想要书名。

最佳答案

使用跟踪

<multiselect
...
track-by="id"
label="name"
...
>

引用:https://vue-multiselect.js.org/#sub-single-select-object

关于vue.js - vue multiselect 1.1.4,通过id选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41562404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com