I was restructing my javascript to be more object oriented. In one
section of my code I had a loop that went through list and called
method on each.
$(''table'').childElements().each(
function(row){
if(this.isSelected(row)){
count++;
}
}
It will not allow me to call the method inside of my object since its
is an anonymous block. Is there a work around to this without having
to attach yet another function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Try function(row) { ... }.bind(this)
On 3/7/08, mtraptor4 <MABekele-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> I was restructing my javascript to be more object oriented. In one
> section of my code I had a loop that went through list and called
> method on each.
> $(''table'').childElements().each(
> function(row){
> if(this.isSelected(row)){
> count++;
> }
> }
>
> It will not allow me to call the method inside of my object since its
> is an anonymous block. Is there a work around to this without having
> to attach yet another function.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
You could do something like:
var count = $$(''#tableId >
*'').findAll(this.isSelected.bind(this)).length;
- kangax
On Mar 7, 6:00 pm, mtraptor4
<MABek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I was restructing my javascript to be more object oriented. In one
> section of my code I had a loop that went through list and called
> method on each.
> $(''table'').childElements().each(
> function(row){
> if(this.isSelected(row)){
> count++;
> }
> }
>
> It will not allow me to call the method inside of my object since its
> is an anonymous block. Is there a work around to this without having
> to attach yet another function.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
On Mar 8, 9:00 am, mtraptor4 <MABek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was restructing my javascript to be more object oriented. In one > section of my code I had a loop that went through list and called > method on each. > $(''table'').childElements().each( > function(row){Doesn''t the childElements function return the immediate descendants of a node? The immediate descendants of a table element are (possibly) text nodes and (certainly) table section elements. If you want the rows of a table, then: $(''table'').rows Since you want to use .each, then perhaps: $A($(''table'').rows).each(...) Or maybe you can use $$(...).> if(this.isSelected(row)){ > count++; > } > } > > It will not allow me to call the method inside of my object since itsCall what method? You passed a reference to an anonymous function to each. Because of the way you have created the function, it is not available to be called as a method (i.e. property that references a function) of any other object. You could change that.> is an anonymous block.Function. -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
table is just a list of <li> inside of <ul>. I just access each <li> and the method isSelected() checks if the check box form has been marked. On Mar 7, 7:59 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Mar 8, 9:00 am, mtraptor4 <MABek...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I was restructing my javascript to be more object oriented. In one > > section of my code I had a loop that went through list and called > > method on each. > > $(''table'').childElements().each( > > function(row){ > > Doesn''t the childElements function return the immediate descendants of > a node? The immediate descendants of a table element are (possibly) > text nodes and (certainly) table section elements. > > If you want the rows of a table, then: > > $(''table'').rows > > Since you want to use .each, then perhaps: > > $A($(''table'').rows).each(...) > > Or maybe you can use $$(...). > > > if(this.isSelected(row)){ > > count++; > > } > > } > > > It will not allow me to call the method inside of my object since its > > Call what method? You passed a reference to an anonymous function to > each. Because of the way you have created the function, it is not > available to be called as a method (i.e. property that references a > function) of any other object. > > You could change that. > > > is an anonymous block. > > Function. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
From the top of my head:
count +=
$(''table'').childElements().select(this.isSelected.bind(this)).length;
--
Christophe Porteneuve aka TDD
tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks
function(row) { ... }.bind(this)
fixed my problem.
On Mar 8, 5:07 am, Christophe Porteneuve
<t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org>
wrote:> From the top of my head:
>
> count +>
$(''table'').childElements().select(this.isSelected.bind(this)).length;
>
> --
> Christophe Porteneuve aka TDD
> t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---