2013-06-25 79 views
0

我想要做類似這樣的事情在CoffeeScript中:調用jQuery庫與CoffeeScript的

word_list = [{ text: "cat", weight: 23 }, { text: "mouse", weight: 10 }, { text: "fox", weight: 5}, { text: "lion", weight: 4}, { text: "giraffe",weight: 3}, {text: "zebra", weight: 2},{ text: "bat", weight: 20 }, { text: "rat", weight: 11 }, { text: "duck", weight: 4}, { text: "dinosaur", weight: 100}, { text: "flamingo",weight: 50}, {text: "kangaroo", weight: 8},] 

$(function() { 
    $("#chart").jQCloud(word_list); 
}); 

我會做出這樣的電話嗎?

jQuery -> 
    $("#chart").jQCloud(word_list); 

或者我需要做的是這樣

$ -> 
    $chart.jQcloud(word_list); 
+0

會是相同的'$(「#chart」)。jQCloud(word_list);'在咖啡 –

回答

2

你可以使用的第一個。或者使它酷似原作:

$ -> 
    $('#chart').jQCloud word_list 

$是一回事jQuery的。假設你已經創建了$chart,那麼第二個也是有效的。

+0

我看,我將如何創建圖表? – Lemonio

+0

'$ chart = $(「#chart」)' – Spencer