3
votes

I got a List in controller:

data = ["one", "two"]

I would love to render it in eex template as:

<script>
var data = ["one", "two"]
</script>

How can I make it, I tried var data = <%= raw(@data) %>, only got var data = [one, two].

1
@OnorioCatenacci I think it's different from that one. - chenxsan
Sorry--should have been more clear. I mean I think you want to use the for comprehension from that answer in your code. - Onorio Catenacci

1 Answers

3
votes

Got the answer from this post,

This is how I make it in the last:

<%= raw(Poison.encode!(@data)) %>