Topic: RJS page.select enumerable methods
I'm trying to iterate over the DOM elements collected by the RJS page.select method. This is intended to update the track numbers of a tracklisting to which users can dynamically add and remove tracks.
page.select(".item").each do |element, index|
page.call 'console.log', index # outputs all indices to the log in Firebug
page.replace_html element, index # replace the HTML of all items with their updated index
If I comment out the page.replace_html element, index line of code, the page.call method happily outputs the index of each element in the collection of DOM elements (div's) of the .item class to the console.
So, I have access to the DOM elements via the element variable, and I have access to the index of each of them via the index variable. How can I output that index into the div? I have not been able to find a clear explanation of this either here (http://www.codyfauser.com/2006/03/16/rjs-element-and-collection-proxies) or here (http://dev.rubyonrails.org/changeset/3754), or in the RJS API (.
Thanks for any help!