Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional params in javascript route - how to indicate None

I have an Action with optional params that looks like this:

def editLink(storyId: Long, linkId: Long, thumbnail: Option[String], title: Option[String], description: Option[String], hidden: Option[Boolean]) = Action.async { ... }

This action is exposed as a JSRoute. I had assumed that providing null as a param to the javascript route from JavaScript would map to Scala's None, but that appears to be incorrect and, instead, it translates to a literal "null" String. How can I indicate that certain query parameters are None when using this action from JavaScript?

like image 621
LuxuryMode Avatar asked Jan 28 '26 17:01

LuxuryMode


1 Answers

Javascript, this wonderful language has two keywords usually used to define the absence of something. null is one of them, undefined is another one. Knowing that when you omit a parameter in a function, it gets passed as undefined, I would imagine that this is what you should use for an optional parameter. As an example :

var f = function (param, optionalParam) {
   console.log(optionalParam);
}

f(1, 2); // prints 2
f(1); // prints undefined
like image 165
Dici Avatar answered Jan 30 '26 12:01

Dici



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!