2 mem fox mem_fox 于 2016.03.01 00:52 提问

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
mem_fox   2016.03.01 07: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)

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!