我试图写一个三条件语句

时间:2014-07-28 22:47:29

标签: javascript coffeescript

你好,我现在有了一行if else语句,我试图将其转换为if else else if语句。

这是coffescript

_index = if $product.find('.dot.active').index() then 0 else 1

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:3)

_index = if $product.find('.dot.active').index() 
   then 0 
else 
   if <some other condition> then <some other result> else <yet another result>

答案 1 :(得分:2)

_index = if $product.find('.dot.active').index() then 0 else if 1 then 2 else 3

我认为这是你正在寻找的东西。

答案 2 :(得分:0)

实际上,使用 if 来实现同样的事情(可以说更清晰)的替代方法是使用开关语句,如下所示:

_index = switch $product.find('.dot.active').index() 
  when false then 0 
  when 1 then 2 
  else 3
相关问题