问题描述
正在处理haml代码。如果要满足条件,我想删除一行或仅将其从表中删除。有什么办法可以完成这项任务?
- if post_name.present?
%td= 'Present'
- elsif post_name.blank?
%td= 'none'
- else
%td= ''
这只是一个例子。如果 post_name.blank?是 true ,那么我要删除或消失该行。
解决方法
根本不渲染它。您可能输入了%tr
,对吗?我想您可以使用...删除它
- @rows.each do |row|
- if row.post_name.present?
%tr
%td = 'Present'
(any other columns you want included)
,
要消失该行,您必须在tr
而非td
上添加条件。
- if post_name.present?
%tr
%td= 'Present'
%td= 'Some other columns'