mem_fox 2016-02-29 16:52 采纳率: 0%
浏览 1903

Slim模板里面通过if判断设定Class标签?

我是通过if else标签重复输出td完成的,有没有更简洁的写法?
- if match_array[0] == false
     td class="success" = obj.shoulder
  - else
     td = obj.shoulder
  - if match_array[1] == false
     td class="success" = obj.chest
  - else
     td = obj.chest
  - if match_array[2] == false
     td class="success" = obj.arm_relaxed
  - else
     td = obj.arm_relaxed
  • 写回答

1条回答 默认 最新

  • mem_fox 2016-02-29 23:43
    关注

    改成这样了,求更简洁写法
    d = obj.member_name
    td class="#{"success" if match_array[0] == false}" = obj.shoulder
    td class="#{"success" if match_array[1] == false}" = obj.chest
    td class="#{"success" if match_array[2] == false}" = obj.arm_relaxed
    td class="#{"success" if match_array[3] == false}" = obj.waist
    td class="#{"success" if match_array[4] == false}" = obj.hip
    td class="#{"success" if match_array[5] == false}" = obj.thigh
    td = edit_with_delete(obj)

    评论

报告相同问题?