简体   繁体   English

带有jQuery的多选下拉列表

[英]Multiple selection dropdown list with jquery

Currently I am customizing multiple selection drop-down list of Multiple Selection Plugin and these are the behaviors that I am going to apply on my customized selection : 当前,我正在自定义“ 多选插件”的多选下拉列表,这些是我将要应用于自定义选择的行为:

  1. When parent is selected, all children will be selected. 选择父级时,将选择所有子级。
  2. When all the children are selected, the parent would be selected too, otherwise if one of children is deselected, then the parent would be deselected too. 当所有子项都被选中时,父项也将被选中,否则,如果其中一个子项被取消选择,则父项也将被取消选择。
  3. When all the children are selected, there should be only parent's name that showed in the selected filed. 当所有孩子都被选中后,所选字段中应仅显示父母的名字。
  4. The sub level should work as the 1st level as well. 子级别也应作为第一级别。

(1), (2), and (4) I have already accomplished it. (1),(2)和(4)我已经完成了。 But for (3), I have not come up with any solution yet. 但是对于(3),我还没有提出任何解决方案。

This is the sample json string of the multi selection : 这是多重选择的示例json字符串:

var _str = '{"10":{"0":"0","1":"DISPONIBILITES","2":"t","style":"font-weight: bold;"},"16":{"0":"0","1":"TRESORERIE NETTE","2":"t","style":"font-weight: bold;"},...."}}}';

Here is the https://jsfiddle.net/skL589uu/7/ that I created. 这是我创建的https://jsfiddle.net/skL589uu/7/

It would be great if anyone here could give me some idea about that. 如果在座的任何人都可以给我一些想法,那就太好了。

You don't have to write any custom logic for that, multi-select.js provides a feature called optGroups . 您不必为此编写任何自定义逻辑, multi-select.js提供了一个称为optGroups的功能。

just group the child items under the parent group in the HTML and the rest is taken care. 只需将子项归类到HTML的父组下,其余的都应当心。

Here is link to official docs, Multi-select OptGroups 这是官方文档的链接, 多选OptGroups

HTML CODE: HTML代码:

  <select multiple="multiple">
    <optgroup label="Group 1">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </optgroup>
    <optgroup label="Group 3">
      <option value="15">15</option>
    </optgroup>
  </select>

JQUERY CODE: JQUERY代码:

$(function() {
   $("select").multipleSelect({
     multiple: true,
     multipleWidth: 55,
     width: '100%'
   });
});

Live Demo @ JSFiddle 现场演示@ JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM