如何在 DHTMLX 组合中生成自定义建议列表

How to generate custom suggestion list in DHTMLX combo

DHTMLX Combo 提供的自动建议列表会在每次击键时更新,但显然仅使用前缀匹配。如何更改逻辑以匹配选项文本中的任何位置。

例如在下面 fiddle:

https://jsfiddle.net/wra8etjw/2/

我希望即使在框中键入 "ee" 时也能显示 "Three" 的建议。我已经阅读了关于 custom filtering 的文档,但是自定义过滤方法和用户定义的函数都没有帮助我。

我正在以基本方式使用 DHTMLX 组合框。也就是说,选项在服务器提供的 HTML 文件中以文字形式存在(它们非常静态),因此永远不会触发 onDynXLS(没有 Ajax 继续)。

我的另一个想法是捕获用户正在输入的当前值,将其保存到某个全局变量中,然后提供一个用户定义的过滤函数,该函数将 return 对当前输入的所有值都为真值存在(不仅仅是作为前缀)。这也失败了,因为显然用户定义的过滤函数只在页面加载时调用,而不是在输入文本中的每次击键时调用。而且,我什至不知道用哪个来捕获Combo输入文本中的击键并获取当前值。

所以我的问题是:

  1. 如何使建议列表显示当前文本作为其中任何位置的子字符串而不只是作为前缀存在的值?
  2. 如何捕获 Combo 的输入文本中的击键并在用户键入时获取当前值?

how to make the list of suggestions show values where the current text exists as a substring anywhere in them, and not just as a prefix?

遗憾的是,如果不修改 dhtmlxCombo 源代码,则无法使用此功能 或者你应该使用服务器端过滤模式,这样你就可以使用onDynXLS事件解决方案。

how to capture keystrokes in the Combo's input text and obtain the current value as the user is typing?

您可以尝试使用"onKeyPressed"事件: https://docs.dhtmlx.com/api__dhtmlxcombo_onkeypressed_event.html

  1. how to make the list of suggestions show values where the current text exists as a substring anywhere in them, and not just as a prefix?

使用enableFilteringMode('between')

  1. how to capture keystrokes in the Combo's input text and obtain the current value as the user is typing?

IMO 最简单的方法是在 Combo 使用的基础 input 元素中附加处理程序。

已更新 fiddle here