导轨 - 表 <TR> - 使用按钮添加过滤器 / Jquery



我想通过点击一个按钮在我的表上实现一个过滤器

我这里有一张表:

    <div class="table-container">
        <table class="table table-filter">
        <tbody>
         <% if current_user %>
         <% @book.each do |book| %>
         <tr data-status = "###">   
<!-- I would like to implement <%= book.style %> inside that data-status, to filter on the type of books   -->
           <td><%= book.name %></td>
           <td> <%= book.author %></td>
          </tr>
         </tbody>
         <% end %>
         <% end %>
     </table>
   </div>

和一个脚本来过滤当我点击按钮

 <button type="button" class="btn btn-success btn-filter" data-target="novel">PC</button>

脚本如下:

<script>
$(document).ready(function () {   
    $('.btn-filter').on('click', function () {
      var $target = $(this).data('target');
      if ($target != 'all') {
        $('.table tr').css('display', 'none');
        $('.table tr[data-status="' + $target + '"]').fadeIn('slow');
      } else {
        $('.table tr').css('display', 'none').fadeIn('slow');
      }
    });
   });
</script>

我不知道如何在Data-status = <% book中传递book类型的值。style %>,甚至当我输入一个文本值,比如Novel,它也不会在表格上过滤。

我真的不知道我错在哪里,我正在寻求帮助。我需要使用content_tag吗?

您可以简单地:

<tr data-status = "<%= book.style %>"> 

最新更新