Tom-Select使用拖放插件时如何保持订单

发布于 2025-02-13 05:48:41 字数 262 浏览 1 评论 0原文

我将tom-select用于多个选择字段, Drop插件

提供给选择的选项是按字母顺序排序的,当我选择某些项目时,一切正常,它们按照预期的是手动分类的顺序将它们保存在db中。问题是,当我重新加载页面时,这些选定的项目还是按字母顺序显示的。有什么方法可以对它们进行自定义方式?

I'm using tom-select for multiple select field with drag & drop plugin

Options provided to the select are alphabetically sorted, everything works fine when I choose some items, they are saved in db in the order I'v sorted them manually, as expected. Problem is that when I reload the page those selected items are shown in alphabetical order anyway. Is there any way to sort them custom way ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2025-02-20 05:48:41

Tom Select将按照您的代码指示订购项目(选定选项)。

new TomSelect('#your-select',{
  items:['a','b']
});

vs

new TomSelect('#your-select',{
  items:['b','a']
});

如果您不告诉汤姆选择要订购的物品的方式,它将使用SELECT中的选项顺序。

Tom Select will order items (selected options) as instructed by your code.

new TomSelect('#your-select',{
  items:['a','b']
});

vs

new TomSelect('#your-select',{
  items:['b','a']
});

If you don't tell Tom Select how you want items ordered, it will use the order of the options in the select.

流云如水 2025-02-20 05:48:41

如果我想通过选择顺序订购,而不是选项顺序,刺激控制器的一部分:

static values = { selectedIds: Array }

...

connect(){
      if(this.selectedIdsValue && this.selectedIdsValue.length > 0) {
        config.items = this.selectedIdsValue
      }
}

I'v resolved it by passing selected ids if I want to have it ordered by selection order, not options order, part of stimulus controller:

static values = { selectedIds: Array }

...

connect(){
      if(this.selectedIdsValue && this.selectedIdsValue.length > 0) {
        config.items = this.selectedIdsValue
      }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文