rails, jquery, javascript, jqvmap can't load multiple countries -
i trying implement jqvmap , have multiple regions selected , colored. how pass variable rails javascript 'selectedregions' variable work? i've tried endlessly can't seem make js read variable correctly.
js code:
<script type="text/javascript"> jquery(document).ready(function() { var areas1=['ca','us']; jquery('#vmap').vectormap({ map: 'world_en', selectedcolor: '#ffc864', selectedregions: areas1 }); }); </script>
the selectedregions variable needs take in format: ['ca', 'us'], when pass in format rails helper method, not work. js experts out there thoughts appreciated!
assuming controller looks this:
def show # set instance variable in controller @areas1 = [ 'ca', 'us' ] # render code.... end
in view selectedregions (assuming it's in erb page) be
<script type="text/javascript"> jquery(document).ready(function() { var areas1=['ca','us']; jquery('#vmap').vectormap({ map: 'world_en', selectedcolor: '#ffc864', selectedregions: [<%= @areas1.map {|str| "'#{ str }'" }.join(',') %>] }); }); </script>
Comments
Post a Comment