在使用 Selectize.js 时,有什么方法可以检测空搜索结果吗? ?
如果用户键入某些内容,但他们没有从下拉列表中获取内容,是否有任何方法可以检测空搜索?
最佳答案
Selectize.js
有一个名为 onType
的事件。当用户键入内容时,将触发 onType 事件。您只需在初始化 Selectize.js
时注册此事件即可。然后,您必须计算过滤器返回的总结果。
实现如下:
$('select[name=country_id]').selectize({
// When user type something, onType event will fire.
onType : function(text) {
if ( ! this.currentResults.items.length) {
$('#country-not-found').removeClass('hide');
} else {
$('#country-not-found').addClass('hide');
}
}
});
有关信息,请访问以下链接:
https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md#callbacks
关于javascript - 检测到搜索没有返回结果 - Selectize.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25739841/