【问题标题】:How to delete a row of table in haml code?如何在haml代码中删除一行表?
【发布时间】:2020-10-14 07:05:24
【问题描述】:

处理haml代码。如果满足条件,我想删除一行或将其从表中消失。有没有办法完成这个任务?

              - if post_name.present?
                %td= 'Present'
              - elsif post_name.blank?
                %td= 'none'
              - else
                %td= ''

这只是一个例子。这里如果 post_name.blank?true 那么我想删除或消失该行。

【问题讨论】:

    标签: ruby-on-rails haml


    【解决方案1】:

    根本不渲染它。您可能有一个%tr 条目,对吧?我想你可以删除它...

    - @rows.each do |row|
      - if row.post_name.present?
        %tr
          %td = 'Present'
          (any other columns you want included)
    

    【讨论】:

      【解决方案2】:

      为了使该行消失,您必须在 tr 而不是 td 上添加条件。

      - if post_name.present?
        %tr
          %td= 'Present'
          %td= 'Some other columns'
      

      【讨论】:

        猜你喜欢
        • 2012-08-05
        • 2011-10-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-15
        • 1970-01-01
        • 2021-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多