cedric
cedric

Reputation: 223

How to loop over an array in CoffeeScript?

I want to loop over the array lists_indexes to update several lists of values in my HTML page.

Currently, I update a single such list through:

$('#List_1').html("<%= escape_javascript(options_for_select(@values, disabled: @disabled)) %>")

How do I loop over lists_indexes to update List_2, ..., List_n?

Upvotes: 3

Views: 414

Answers (1)

Zahid
Zahid

Reputation: 1830

What you need is this, you dont need to loop over in CoffeScript, you can loop via ruby

<% list_indexes.each do |i| %>
$("#List_<%= i %>").html("<%= escape_javascript(options_for_select(@values, disabled: @disabled)) %>")
<% end %>

Upvotes: 5

Related Questions