第一个和第二个有什么不同?第一个按预期工作,但第二个没有达到我的预期。在第一个中,我通过 callToPhotos 间接进行调用,但在第二个中,我立即调用 getPhotos 并传入相册。为什么以及如何不同?
$.ajax
method:'get'
url: '/slides/facebook-albums'
success: (albums) ->
renderAlbums(albums)
callToPhotos(albums)
renderAlbums = (albums) ->
for album in albums
$('#facebook .main').append("<div id='#{ album['id'] }' class='album-info'><a class='#{album['id']} fb-album' href='#'>#{album['name']}</a>
<img src=#{album['cover_photo']} width='100' height= '100' class='#{album['id']} fb-album'></div>")
callToPhotos = (albums) ->
for album in albums
getPhotos(album)
getPhotos = (album) ->
$.ajax
method: "get"
url: "/slides/#{album['id']}/photos"
success: (photos) ->
renderPhotos(photos, album['id'])
--
$.ajax
method:'get'
url: '/slides/facebook-albums'
success: (albums) ->
renderAlbums(albums)
# callToPhotos(albums)
getPhotos(albums)
renderAlbums = (albums) ->
for album in albums
$('#facebook .main').append("<div id='#{ album['id'] }' class='album-info'><a class='#{album['id']} fb-album' href='#'>#{album['name']}</a>
<img src=#{album['cover_photo']} width='100' height= '100' class='#{album['id']} fb-album'></div>")
callToPhotos = (albums) ->
for album in albums
getPhotos(album)
getPhotos = (albums) ->
for album in albums
$.ajax
method: "get"
url: "/slides/#{album['id']}/photos"
success: (photos) ->
renderPhotos(photos, album['id'])