다음을 수행하는 방법을 배우고 혼란 스럽습니다. 감사!이 jQuery를 coffeescript로 작성하는 방법은 무엇입니까?
$.each($(".nested-fields"), function(intIndex) {$(this).find(".set").html(intIndex+1);;});
다시 한 번 감사드립니다.
다음을 수행하는 방법을 배우고 혼란 스럽습니다. 감사!이 jQuery를 coffeescript로 작성하는 방법은 무엇입니까?
$.each($(".nested-fields"), function(intIndex) {$(this).find(".set").html(intIndex+1);;});
다시 한 번 감사드립니다.
원래 자바 스크립트 (또는)과 같이 작성해야 수를, 어떻게 커피 스크립트이 자바 스크립트를 작성하는 을해야한다 모양은 다음과 같습니다.
fields = $('.nested-fields')
for field, i in fields
set = $(field).find('.set')
set.html i+1
또는개인적 $(field).find('.set').html i+1 for field in fields
for field, i in $(".nested-fields")
$(field).find('.set').html(i+1)
((;) for 루프와 배열을 통해이 반복합니다.)
또는 당신은 $ .each 사용하려는 경우 :
가$.each $(".nested-fields"), (i) ->
$(this).find('.set').html(i+1)
BTW 제목이 조금 부정확;
$('.nested-fields').each(function(i){
$(this).find('.set').html(i+1)
})
그래서
$('.nested-fields').each (i) ->
$(this).find('.set').html i+1
보다 읽기 쉬운 버전 수 :)
I는 coffeescrip의 for .. in ..
좋아하지만 JQuery와 오브젝트로서 반복기가 다음의 구조를 이용하여 천공 하였다
for td in $('td.my_class')
$td = $(td)
..
그래서 I는 항목마다 JQuery와 객체에 사용 가능한 기능 정의를 :
$.fn.items = -> $.map(this, $)
지금 커피 스크립트와 탐색은 간단하다 :
for $td in $('td.my_class').items()
$td <-- is a JQuery object
$(). 각. :)에 대한 멋진 캐치 필드의 필드에 대한 .html i + 1은 * 더 * 읽기 쉽지 않습니다.) 적어도 .html (i + 1)'할 것입니다. – arnaud576875
나는 마지막 것을 좋아하지만, 모든 말로 가서 $ { '중첩 필드 (nested-fields)}'필드에 넣는다. 그리고'.html (i + 1)'이 읽기 쉽다는 것을 @arnaud에 동의합니다. –