在带有bootstrap-vue的vue项目中,我搜索了一下select组件是如何工作的https://bootstrap-vue.js.org/docs/components/form-select/,没有看到它有任何过滤选项吗?如果没有,还有没有其他带筛选选项的bootstrap-vue选择组件/库?
"bootstrap-vue": "^2.1.0"
"vue": "^2.6.10"谢谢!
发布于 2020-06-21 15:43:08
有一种可能性。使用b-form-datalist。请参阅手册https://bootstrap-vue.org/docs/components/form-input中的示例
<template>
<b-form-input list="my-list-id"></b-form-input>
<datalist id="my-list-id">
<option>Manual Option</option>
<option v-for="size in sizes">{{ size }}</option>
</datalist>
</template>
<script>
export default {
data() {
return {
sizes: ['Small', 'Medium', 'Large', 'Extra Large']
}
}
}
</script>发布于 2020-06-06 05:51:10
我为自己做了些东西。以下是代码片段,以防万一。我使用了一个表,因为我想显示更多的列,但它可以交换为其他东西,比如跨度列表或按钮。
<template>
<div>
<div>
<b-form-input
class='search-input'
type='search'
v-model='filterCriteria'
v-on:click='toggleDropDown()'
v-on:keyup.enter='selectItem()'
:placeholder='placeholder'>
</b-form-input>
</div>
<div>
<b-collapse id='drop-down'>
<b-table
no-border-collapse
ref='collapsibleTable'
responsive='sm'
selectable
select-mode='single'
sticky-header='200px'
thead-class='d-none'
v-model='filteredRows'
:fields='fields'
:filter='filterCriteria'
:items='items'
:sort-by.sync='sortBy'
:sort-desc.sync='sortDesc'
@row-selected='rowSelected'>
</b-table>
</b-collapse>
</div>
</div>
</template>
<script>
export default {
data() {
return {
filterCriteria: '',
filteredRows: []
}
},
methods: {
toggleDropDown() {
this.$root.$emit('bv::toggle::collapse', 'drop-down')
},
selectItem() {
if (this.filteredRows.length === 1) {
this.$refs.collapsibleTable.selectRow(0)
}
},
rowSelected(rowArray) {
// No rows or 1 row can be selected
if (rowArray.length === 1) {
this.$emit('item-selected', rowArray[0])
this.filterCriteria = rowArray[0][this.display]
this.toggleDropDown()
}
}
},
props: {
display: {
required: true,
type: String
},
fields: {
required: true,
type: Array
},
items: {
required: true,
type: Array
},
placeholder: {
required: false,
default: 'Select'
},
sortBy: {
required: true,
type: String
},
sortDec: {
default: false,
required: false
}
}
}
</script>https://stackoverflow.com/questions/59900511
复制相似问题