2012-07-05 47 views
0

显得比较直截了当:这是如何不是咖啡脚本中的功能?

_.each words, (val, key) -> $(".word_choice")[key].html val 

返回:

$(".word_choice")[key].html is not a function 
[Break On This Error] 

return $(".word_choice")[key].html(val); 

想不通这一点。我使用这个参考:

http://autotelicum.github.com/Smooth-CoffeeScript/literate/underscore.html#each

+0

啊我也是!我认为这是一个非常诚实的问题,用很好的参考文字说得很好?感谢+1 – Trip

回答

6

当一个jQuery对象访问由索引的元素,你回来一个普通的HTML元素,而不是另一个jQuery对象。改为使用.eq

_.each words, (val, key) -> $(".word_choice").eq(key).html val