admin管理员组文章数量:1200358
Just trying to learn and confused on how to do the following. Thanks!
$.each($(".nested-fields"), function(intIndex) {$(this).find(".set").html(intIndex+1);;} );
Thank you again.
Just trying to learn and confused on how to do the following. Thanks!
$.each($(".nested-fields"), function(intIndex) {$(this).find(".set").html(intIndex+1);;} );
Thank you again.
Share Improve this question edited Sep 15, 2011 at 12:05 Arnaud Le Blanc 99.9k24 gold badges211 silver badges196 bronze badges asked Sep 15, 2011 at 12:00 Daniel FischerDaniel Fischer 3,0621 gold badge28 silver badges50 bronze badges3 Answers
Reset to default 20The original javascript could (or should) be written like this:
$('.nested-fields').each(function(i){
$(this).find('.set').html(i+1)
})
so
$('.nested-fields').each (i) ->
$(this).find('.set').html i+1
a more readable version could look like this:
fields = $('.nested-fields')
for field, i in fields
set = $(field).find('.set')
set.html i+1
or
$(field).find('.set').html i+1 for field in fields
for field, i in $(".nested-fields")
$(field).find('.set').html(i+1)
(This iterates over the array with a for (;;) loop.)
Or if you want to use $.each:
$.each $(".nested-fields"), (i) ->
$(this).find('.set').html(i+1)
BTW the title is a little incorrect; should be how to write this Javascript in Coffeescript ;)
Personally I like the for .. in ..
of coffeescrip but I was boring using the following structure to have the iterator as JQuery object :
for td in $('td.my_class')
$td = $(td)
..
So I defined a items function available to each JQuery object:
$.fn.items = -> $.map(this, $)
Now the navigation with coffeescript is simpler :
for $td in $('td.my_class').items()
$td <-- is a JQuery object
本文标签: javascriptHow would I write this jQuery in coffeescriptStack Overflow
版权声明:本文标题:javascript - How would I write this jQuery in coffeescript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738615226a2102868.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论