bootstrap 多选下拉禁用过滤不起作用

bootstrap multiselect dropdown disable Filtering not working

一个页面上有多个 select 下拉菜单,因此我们对所有下拉菜单都使用通用选项,但希望对特定下拉菜单使用 select 过滤选项。

选项:

function getOptions(isFilter) {
    return {
        enableFiltering: isFilter,
        enableCaseInsensitiveFiltering: true,
        filterPlaceholder: 'Search ...',
        nonSelectedText: node,
        numberDisplayed: 1,
        maxHeight: 400,
    }
}

$('#DDLState').multiselect(getOptions(true)); //enable Filtering true working ok

$('#DDLCity').multiselect(getOptions());//enable Filtering false not working

但是两者都启用了过滤。

你的问题在这个属性:

enableCaseInsensitiveFiltering: true,

改为:

enableCaseInsensitiveFiltering: isFilter,

来自documentation

enableCaseInsensitiveFiltering: The filter as configured above will use case sensitive filtering, by setting enableCaseInsensitiveFiltering to true this behavior can be changed to use case insensitive filtering.

片段:

function getOptions(isFilter) {
    return {
        enableFiltering: isFilter,
        enableCaseInsensitiveFiltering: isFilter,
        filterPlaceholder: 'Search ...',
        nonSelectedText: 'Check an option!',
        numberDisplayed: 1,
        maxHeight: 400,
    }
}

$('#DDLState').multiselect(getOptions(true));
$('#DDLCity').multiselect(getOptions());
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css">
<script src="https://rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"></script>


<div class="container-fluid">
    <div class="row">
        <div class="col-xs-6 col-md-4">
            <select id="DDLState" multiple="multiple">
                <option value="cheese">Cheese</option>
                <option value="tomatoes">Tomatoes</option>
                <option value="mozarella">Mozzarella</option>
                <option value="mushrooms">Mushrooms</option>
                <option value="pepperoni">Pepperoni</option>
                <option value="onions">Onions</option>
            </select>
        </div>
        <div class="col-xs-6 col-md-4">
            <select id="DDLCity" multiple="multiple">
                <option value="cheese">Cheese</option>
                <option value="tomatoes">Tomatoes</option>
                <option value="mozarella">Mozzarella</option>
                <option value="mushrooms">Mushrooms</option>
                <option value="pepperoni">Pepperoni</option>
                <option value="onions">Onions</option>
            </select>
        </div>
    </div>
</div>