Tom-Select(或 Selectize.js)选项组的远程数据
我正在尝试使用远程数据进行 tom-select (https://tom-select.js .org/examples/optgroups/)。我不知道如何使用远程数据配置选项组。我选择加载远程数据,如下所示:
"optgroup": "1 Materials | 1.2 Gravel",
"value": 65,
"label": "1.2.1 Tanks"
从文档中我得到的印象是您设置了 optgroupField: 'optgroup'
并且选项组将自动设置。我需要将 optgroups 数组添加到我的 JSON 数据中吗?我似乎在任何地方都找不到带有选项组的远程数据的任何示例。
tom-select 共享 Selectize.js 中的大部分代码,因此我也对其进行交叉标记。
I am trying to use remote data for tom-select (https://tom-select.js.org/examples/optgroups/). I am at a loss how to configure option groups with remote data. I have the select loading with remote data like this:
"optgroup": "1 Materials | 1.2 Gravel",
"value": 65,
"label": "1.2.1 Tanks"
From the docs I got the impression that you set optgroupField: 'optgroup'
and the option groups would be set automatically. Do I need to add the optgroups array to my JSON data? I can't seem to find any examples of remote data with option groups anywhere.
tom-select shares much of it's code from Selectize.js so I am cross tagging this also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 selectize 世界中找到了一个解决方案:
https://github.com /selectize/selectize.js/issues/151#issuecomment-111056161
我添加了一个组 ID:
重置组字段:
optgroupField: 'optgroup_id'
然后在load
中的 json 回调之后添加了这个:我还在尝试添加第二个
optgroups
json 数组,其中仅包含组以避免循环通过所有选项。我希望有一个更好的答案 - 对此将保持开放。希望这对其他人有帮助。
I found a solution in the selectize world:
https://github.com/selectize/selectize.js/issues/151#issuecomment-111056161
I added a group id:
Reset the group field:
optgroupField: 'optgroup_id'
then added this after the json callback inload
:I am also playing around with adding a second
optgroups
json array with just the groups to avoid cycling through all the options.I hope there is a better answer - will leave this open for that. Hoping this helps someone else.
使用 TomSelect,您可以将远程数据格式化为选项组,如下所示:
然后,您的数据应包含每个项目的
optgroup
属性。With TomSelect you can format remote data into option groups like this:
Your data should then include an
optgroup
property for each item.