我想在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 :(得分:2)
你可以使用第一个。或者使它与原始版本完全相同:
$ ->
$('#chart').jQCloud word_list
但$
与jQuery是一回事。假设您已创建$chart
,则第二个也有效。