Forgot Element#hasClassName
elements = elements.partition(function(d) { return
d.hasClassName("new") }).flatten();
(the 'partition' solution works only for two classes, more than that
and you need something else)
polomasta wrote:
> it seems that result is getting populated correctly, but it never
> actually changes anything on the page. I tried doing: leads.innerHTML
> = result; and it just inserted a bunch of [htmlObject] text into the
> page.
Both the method I suggest and the code you pasted will sort *the
array* of elements, not the elements in the DOM. If you want that to
reflect that on the DOM, Element#insert is your friend.
elements.each(Element.insert.curry("container")) // this will insert
them in the order they are in the array
Best,
-Nicolas
On Feb 7, 2008 2:43 PM, Nicolás Sanguinetti <[EMAIL PROTECTED]> wrote:
> If you can do it in the server, do it there :) If not (maybe the data
> is created in js and it's still not available in the server, for
> example), a possibility is to use Enumerable#partition:
>
> $$(".new, .read").partition(function(d) { return
> d.className.match(/new/) }).flatten();
>
> http://prototypejs.org/api/enumerable/partition
>
> Best,
> -Nicolas
>
> (ps: wow, first time I find an actual use for Enumerable#partition)
>
>
> On Feb 1, 2008 12:04 PM, Wizz <[EMAIL PROTECTED]> wrote:
> >
> > On 31 jan, 21:47, polomasta <[EMAIL PROTECTED]> wrote:
> > > I guess they can the first time. However, a button in the div can be
> > > clicked to change its status (class) from "new" to "read" or vice
> > > versa... when this happens I want to resort the divs without having to
> > > reload everything from the server again.
> > >
> > > Does that make sense?
> > >
> > > On Jan 24, 7:07 pm, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
> > >
> > > > On Jan 24, 2008 4:10 PM, polomasta <[EMAIL PROTECTED]> wrote:
> > >
> > > > > I have a script that pulls in a bunch of data to my page and parses it
> > >
> > > > Is this data being pulled in through an Ajax request? Why can't the
> > > > data be sorted on the server?
> > >
> > > > -justin
> > I would suggest making 2 arrays with the 'new' divs and the 'read'
> > divs and merging the afterwards.
> >
> > sortMessages($('container'));
> >
> > function sortMessages(container) {
> > var read = container.select('div.read');
> > var new = container.select('div.new');
> > var result = $A([]);
> > return result.concat(new, read);
> > }
> >
> > Haven't tested it though... but this is the general idea
> >
> > Greetz,
> >
> > Wizz
> >
> > > >
> >
>
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---