I have been reading the documentation at: http://www.sergiopereira.com/articles/prototype.js.html One of the examples does this: var someNodeList = $(''lstEmployees'').getElementsByTagName(''option''); var nodes = $A(someNodeList); nodes.each(function(node){ alert(node.nodeName + '': '' + node.innerHTML); }); How can I access the array index as well as the node value? The reference mentions that the Enumerable.each() function (I assume this is the same one) can access the index, but I don''t quite see it. I''m sure it''s something incredibly obvious that I''ll end up smacking myself over... but who knows? Thanks again guys. -Greg
I believe you simply have to include a second parameter to your iterator function (which will be the index). nodes.each(function(node, index){ alert(node.nodeName + '': '' + node.innerHTML); }); -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Greg Militello Sent: Thursday, February 09, 2006 2:41 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] each() I have been reading the documentation at: http://www.sergiopereira.com/articles/prototype.js.html One of the examples does this: var someNodeList = $(''lstEmployees'').getElementsByTagName(''option''); var nodes = $A(someNodeList); nodes.each(function(node){ alert(node.nodeName + '': '' + node.innerHTML); }); How can I access the array index as well as the node value? The reference mentions that the Enumerable.each() function (I assume this is the same one) can access the index, but I don''t quite see it. I''m sure it''s something incredibly obvious that I''ll end up smacking myself over... but who knows? Thanks again guys. -Greg _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
I suppose that would make sense.... See, I figured it was obvious. :) Silly me. -Greg On Feb 9, 2006, at 3:42 PM, Ryan Gahl wrote:> I believe you simply have to include a second parameter to your > iterator > function (which will be the index). > > nodes.each(function(node, index){ > alert(node.nodeName + '': '' + node.innerHTML); > }); > > -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of > Greg > Militello > Sent: Thursday, February 09, 2006 2:41 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] each() > > I have been reading the documentation at: > http://www.sergiopereira.com/articles/prototype.js.html > > One of the examples does this: > > var someNodeList = $(''lstEmployees'').getElementsByTagName(''option''); > var nodes = $A(someNodeList); > > nodes.each(function(node){ > alert(node.nodeName + '': '' + node.innerHTML); > }); > > How can I access the array index as well as the node value? The > reference mentions that the Enumerable.each() function (I assume this > is the same one) can access the index, but I don''t quite see it. I''m > sure it''s something incredibly obvious that I''ll end up smacking > myself over... but who knows? > > > Thanks again guys. > -Greg > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > The information transmitted in this electronic mail is intended > only for the > person or entity to which it is addressed and may contain > confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited. If you received this in error, please contact the > sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Nah, a lot of these things aren''t obvious or well documented. You just have to look through the code sometimes =). -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Greg Militello Sent: Thursday, February 09, 2006 2:58 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] each() I suppose that would make sense.... See, I figured it was obvious. :) Silly me. -Greg On Feb 9, 2006, at 3:42 PM, Ryan Gahl wrote:> I believe you simply have to include a second parameter to your > iterator > function (which will be the index). > > nodes.each(function(node, index){ > alert(node.nodeName + '': '' + node.innerHTML); > }); > > -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of > Greg > Militello > Sent: Thursday, February 09, 2006 2:41 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] each() > > I have been reading the documentation at: > http://www.sergiopereira.com/articles/prototype.js.html > > One of the examples does this: > > var someNodeList = $(''lstEmployees'').getElementsByTagName(''option''); > var nodes = $A(someNodeList); > > nodes.each(function(node){ > alert(node.nodeName + '': '' + node.innerHTML); > }); > > How can I access the array index as well as the node value? The > reference mentions that the Enumerable.each() function (I assume this > is the same one) can access the index, but I don''t quite see it. I''m > sure it''s something incredibly obvious that I''ll end up smacking > myself over... but who knows? > > > Thanks again guys. > -Greg > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > The information transmitted in this electronic mail is intended > only for the > person or entity to which it is addressed and may contain > confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited. If you received this in error, please contact the > sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs