user79074
user79074

Reputation: 5270

How to convert an Iterable to a js.Dynamic

I have some optional parameters I want to use to initialise a JQuery widget that are passed as

Iterable[(String, String)]

What is the best way to convert this object to a js.Dynamic?

Upvotes: 1

Views: 104

Answers (1)

sjrd
sjrd

Reputation: 22085

Probably the following:

val seq = iterable.toSeq
val dict = js.Dictionary(seq: _*)
val dynamic = dict.asInstanceOf[js.Dynamic]

You can of course make it into a single expression:

js.Dictionay(iterable.toSeq: _*).asInstanceOf[js.Dynamic]

Upvotes: 2

Related Questions