Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 724
cedric Avatar asked Feb 15 '26 01:02

cedric


1 Answers

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 %>
like image 92
Zahid Avatar answered Feb 16 '26 18:02

Zahid



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!