从其事件处理程序之一获取 Selectize.js 元素的基础输入元素

Getting the Underlying Input Element of a Selectize.js element from one of its event handlers

事实证明,这比我原先预期的要困难得多,但希望我只是遗漏了一些东西。

我正在使用 Selectize.js 填充表单中的某些字段。 The field sets are always the same (one text element initialized with .selectize(), and two other text elements with similar Ids. The selectize drop-down is populated via remote API calls and when an item is selected I通过 selectize 的 onChange 事件自动填充其他字段。

问题是我想从原始文本框中检索数据属性,每个选择都是从 onChange 处理程序内部初始化的,以确定应该填充哪些附加字段。我无法确定从哪里获取原始元素,因为 API 中没有任何内容对此进行讨论,并且在调试时我也无法找到实际元素。

有谁知道如何访问底层输入元素?

在使用开发人员工具进行更多挖掘后,事实证明您可以从事件处理程序中获取底层输入元素:

this.$input

其中 $input 是基础元素的 jQuery 对象。不幸的是,这不在文档中。

用法:

$('.lookup').selectize({
    onChange: function(value) {
        var data = this.$input.data('stuff');
    }
 });