Is there a JsAnd or JsOr when generate JS in lift?

2019-08-11 16:47发布

问题:

I know this is very much a noob question...

I see lift provides utilities methods to generate javascript commands. I want to do the equivalent of:

JsIf((JsEq(ValById("disable-production"),JsTrue) || JsEq(ValById("disable-production"), JsTrue) , {
        Alert("Do something interesting...")
      })

Thanks.

回答1:

Yes, there is:

import net.liftweb.http.js.JsCmds._
import net.liftweb.http.js.JE._

val conditional = JsIf(
  JsOr(
    JsEq(ValById("disable-production"), JsTrue),
    JsEq(ValById("disable-something-else"), JsTrue)
  ),
  Alert("Do something interesting...")
)


回答2:

You would probably be better off writing this directly in string form and then evaluating it using JsExp.strToJValue(<your expression>).

However, the direct answer to your question would be JE.JsOr.

JsIf((JE.JsOr(JsEq(ValById("disable-production"),JsTrue),
             JsEq(ValById("disable-production"), JsTrue)) , {
    Alert("Do something interesting...")
  })