[英]Choices.js Full text search filter issue
I am using the choices.js library for searching data from the dropdown menu.我正在使用choices.js库从下拉菜单中搜索数据。
when I type in the search box.当我在搜索框中输入时。 it shows me first-word exact matching data in suggestions.
它向我展示了建议中的第一个单词完全匹配的数据。
for example:例如:
[mid america, america ]
when I search for america
it shows me only america
option in the dropdown, it will not showing mid america
option当我搜索
america
时,它在下拉列表中只显示america
选项,它不会显示mid america
选项
here are the choices.js options that I am using for the search filter.这是我用于搜索过滤器的 choices.js 选项。
silent: false,
items: [],
choices: [],
renderChoiceLimit: -1,
maxItemCount: -1,
addItems: true,
addItemFilter: null,
removeItems: true,
removeItemButton: false,
editItems: false,
allowHTML: true,
duplicateItemsAllowed: true,
delimiter: ',',
paste: true,
searchEnabled: true,
searchChoices: true,
searchFloor: 1,
searchResultLimit: 4,
searchFields: ['label', 'value'],
position: 'auto',
resetScrollPosition: true,
shouldSort: true,
shouldSortItems: false,
sorter: () => {...},
placeholder: true,
placeholderValue: null,
searchPlaceholderValue: null,
prependValue: null,
appendValue: null,
renderSelectedChoices: 'auto',
loadingText: 'Loading...',
noResultsText: 'No results found',
noChoicesText: 'No choices to choose from',
itemSelectText: 'Press to select',
addItemText: (value) => {
return `Press Enter to add <b>"${value}"</b>`;
},
maxItemText: (maxItemCount) => {
return `Only ${maxItemCount} values can be added`;
},
valueComparer: (value1, value2) => {
return value1 === value2;
},
classNames: {
containerOuter: 'choices',
containerInner: 'choices__inner',
input: 'choices__input',
inputCloned: 'choices__input--cloned',
list: 'choices__list',
listItems: 'choices__list--multiple',
listSingle: 'choices__list--single',
listDropdown: 'choices__list--dropdown',
item: 'choices__item',
itemSelectable: 'choices__item--selectable',
itemDisabled: 'choices__item--disabled',
itemChoice: 'choices__item--choice',
placeholder: 'choices__placeholder',
group: 'choices__group',
groupHeading: 'choices__heading',
button: 'choices__button',
activeState: 'is-active',
focusState: 'is-focused',
openState: 'is-open',
disabledState: 'is-disabled',
highlightedState: 'is-highlighted',
selectedState: 'is-selected',
flippedState: 'is-flipped',
loadingState: 'is-loading',
noResults: 'has-no-results',
noChoices: 'has-no-choices'
},
// Choices uses the great Fuse library for searching. You
// can find more options here: https://fusejs.io/api/options.html
fuseOptions: {
includeScore: true
}
If there is no mistake this should work.如果没有错误,这应该可以工作。 For example,
ban
will match Bangladesh , Albania and Lebanon .例如,
ban
将匹配Bangladesh 、 Albania和Lebanon 。
document.addEventListener('DOMContentLoaded', function() { const choicesBasic = new Choices('#countries', { searchPlaceholderValue: "Search a Country", position: 'bottom', choices: [ {value: 'af', label: 'Afghanistan'}, {value: 'al', label: 'Albania'}, {value: 'ao', label: 'Angola'}, {value: 'al', label: 'Anguilla'}, {value: 'bd', label: 'Bangladesh'}, {value: 'lb', label: 'Lebanon'}, {value: 'pk', label: 'Pakistan'}, {value: 'tj', label: 'Tajikistan'}, {value: 'tm', label: 'Turkmenistan'}, {value: 'uz', label: 'Uzbekistan'}, ], searchFields: ['label', 'value'], }); });
* { box-sizing: border-box; }
<link rel="stylesheet" href="https://choices-js.github.io/Choices/assets/styles/choices.min.css" crossorigin="anonymous" /> <script src="https://choices-js.github.io/Choices/assets/scripts/choices.min.js" crossorigin="anonymous"></script> <select id="countries"> <option value="">Select a Country</option> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.