I'm trying to do this in coffeescript,
Specifically I'm trying to add handlers to my jQWordCloud to get the label for the word being clicked on
In my coffeescript version
while i < @counts.length
x = @counts[i]
@tag_list.push
text: x.label
weight: x.count
handlers:
click: ->
temp = x
->
alert "it worked for " + temp.label
()
++i
I get an unexpected TERMINATOR error presumably because of the (), but if you notice on the jsfiddle, removing that breaks the handler
The usual CoffeeScript approach to this problem is to use
do
:Then just use a plain
for ... in
instead of thewhile
loop so that you don't have to muck around with the indexes; something more like this:Demo: http://jsfiddle.net/ambiguous/3W9YC/
Or you could use a loop comprehension like this:
and avoid the
push
calls.Demo: http://jsfiddle.net/ambiguous/3W9YC/1/
BTW, you can use CoffeeScript at jsfiddle.net by selecting it in the Languages panel in the sidebar.