我有一个selectize.js下拉列表,它使用ajax从服务器提供项目列表.服务器从给定的字符串提供自动完成,因此我不需要选择性的本机过滤.此外,我真的需要关闭它:服务器输出可能完全不同于标准的字符串搜索算法.数据被精确地转换为javascript对象,但是selectize甚至没有显示弹出窗口,因为这些项目与selectize的过滤器不匹配.如何禁用或修改本机过滤并匹配突出显示algorythm?使用内置选项还是使用插件?或唯一的方法,是修改源?
编辑:
searchField:false/function()不起作用(文档没有提到它们作为可用的选项值)
EDIT2:
最终得出了这个技巧:为每个项添加一个假字段,为其分配一个搜索字符串,并告诉selectize使用它作为searchField.但显然,应该有更好的方法,所以问题仍然存在.
小智 9
我使用此解决方案(如果服务器的结果正确排序):
score: function() { return function() { return 1; }; },
Run Code Online (Sandbox Code Playgroud)
或者这个(如果需要订购)
score: function(search) {
var score = this.getScoreFunction(search);
return function(item) {
return 1 + score(item);
};
},
Run Code Online (Sandbox Code Playgroud)
Sifter使用分数函数进行过滤.得分结果必须> 0.
小智 2
我需要禁用搜索,这样 iPhone 就不会显示键盘。我选择的解决方案通过挂钩 selectize 设置使搜索字段变为只读(不修改实际源,因此 selectize 仍然可更新)。这是代码,如果有人需要的话:
// Put this code after you've included Selectize
// but before any selectize fields are initialized
var prevSetup = Selectize.prototype.setup;
Selectize.prototype.setup = function () {
prevSetup.call(this);
// This property is set in native setup
// Unless the source code changes, it should
// work with any version
this.$control_input.prop('readonly', true);
};
Run Code Online (Sandbox Code Playgroud)