JQuery MultiSelect程序选择

时间:2017-06-29 21:36:40

标签: jquery multi-select

使用http://crlcu.github.io/multiselect/我无法以编程方式“重置”'来自'& '到'选择。嗯,它第一次工作,但后来失败了。

这个小提琴是https://jsfiddle.net/24690u7c/。你可以移动左边的东西。没有问题。第一次点击“重置”按钮一切正常。然后,后续的重置尝试失败。重置功能执行以下操作:

  • 将所有项目移至左侧
  • 选择应该在右侧的项目
  • 将选定项目向左移动到右侧

......问题似乎出现在选择步骤中:我看到“已选择”属性已设置,但项目未被视为已选择插件。

任何人都能告诉我这里缺少什么?

$("#resetDefaults").on("click", function(event) {  
   $('#multiselect_leftAll').trigger('click');          // all to the left
   $("#multiselect option").each(function() {
     if ($(this).val() == "A"  || $(this).val() == "B") {
       $(this).attr('selected', true);                  // select what should be on the right
     }                                                  // ... this is I think the issue :-(
   });
   $('#multiselect_rightSelected').trigger('click');    // move the selected right
});

1 个答案:

答案 0 :(得分:0)

好的,在修补这个之后,我能做的最简单的事情就是:

A)将class='defaultColumn'添加到我想要的每个项目中,然后重置'选择正确

B)将上面的代码段改为:

 $("#resetDefaults").on("click", function(event) {
    $('#multiselect_leftAll').trigger('click');                  // all to the left
    var MS = $("#multiselect").data('crlcu.multiselect');        // grab the current Multiselect instance
    var $options = $("#multiselect").children('.defaultColumn'); // grab all options of interest
    MS.moveFromAtoB(MS.$left, MS.$right, $options);              // call the internal function to move the selected options over
 });

......我猜这是最简单的。谢天谢地我凿了一个像这个一样干净的文库: - )