简体   繁体   English

在选项选择上,显示/隐藏表行并排序

[英]on option select, show/hide table row and sort

This block of code verify if all of codes is checked. 此代码块验证是否检查了所有代码。 I am looking for a way to check if at least one of the codes is checked, instead. 我正在寻找一种方法来检查是否至少检查了其中一个代码。

function containsAny(needles, haystack){ 
  for(var i = 0 , len = needles.length; i < len; i++){
    if($.inArray(needles[i], haystack) == -1) return true;
  }
  return false;
}

I have a full working example here: http://jsfiddle.net/v7wt5eop/ 我在这里有一个完整的工作示例: http : //jsfiddle.net/v7wt5eop/

How to see this behavior: 如何看这种行为:

  1. In the selectbox click Deselect All 选择框中单击全部取消选择
  2. Check A 检查A
  3. Line 2 and 3 of the table should be unfaded because A is one of the codes 该表的第2行和第3行应该不褪色,因为A是代码之一

And the rows that are with the class row-disabled should be at the end of the table. 并且具有row-disabled的类的row-disabled应位于表的末尾。 I am using Bootstrap Sortable , but couldn't figure out how to do it. 我正在使用Bootstrap Sortable ,但无法弄清楚该怎么做。 So everytime I click in an option in the selectbox it should re-order the table. 因此,每当我在选择框中单击一个选项时,都应该对表重新排序。

Your function containsAny should be 您的功能containsAny应该

function containsAny(needles, haystack){ 
  for(var i = 0 , len = needles.length; i < len; i++){
    if($.inArray(needles[i], haystack) != -1) return false;
  }
  return true;
}

To sort every time you check/uncheck 每次您选中/取消选中时进行排序

$('.selectpicker').on('change', function() {
  var list = [];
  $('.selectpicker :selected').each(function(i, selected) {
    //Removed the irrelevant codes
  });

  $('.CodeCheck').each(function() {
    //Removed the irrelevant codes
  });

  el = $(".table tbody tr.row-disabled:first-child");
  $(".table tbody tr").not(".row-disabled").each(function() {
    $(this).insertBefore(el);
  });
});

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

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