Hello there,
giles goat boy a écrit :
> to date on the Flash widget stuff. First I tried to put the JS vars in
> the "parameters" var of the new Ajax.Request in the
> Form.Element.Observer, but it appears to be evaluating those vars
> immediately, rather than passing them to Ajax.Request with the idea
> "these are vars to evaluate every time you make a request". I tried
Which is the nominal behavior of JS: if you use variables at some point,
they get evaluated immediately.
> storing the field observer in a variable and creating a new one each
> time, which goes into that variable, on the hopes that would cause
> garbage collection to destroy the old field observers each time the var
> was reallocated, or whatever, but that didn't work either.
>
> In fact, what happened there, I ended up with a new observer with the
> correct Ajax.Request parameters each time -- but the old ones weren't
> destroyed, so I had a huge problem on my hands.
I'm not too sure how you go about this. No observer class wires
automatically to an Ajax call: it just invokes its callback method, as
passed at construction time (third argument for time-based observers,
second one for event-based observers).
So this method you're passing could very well build the new Ajax.Request
object and pass it your JS variables among the parameters, which would
get evaluated dynamically at the moment the line is run.
Ajax.Request objects are not designed to be reused, so creating a new
one in the callback function every time it's needed is no problem. As a
local variable (or not even a variable!), it will get garbage-collected
properly.
Something like:
var flashState1 = 'blah';
var flashState2 = 42;
new Form.Element.Observer('myFormElementID', 500, function(elt, value) {
new Ajax.Request('/your/server/script', {
// whatever other options you use, e.g. method, onSuccess...
parameters: { value: value, fs1: flashState1, fs2: flashState2 }
});
});
And there you go! Since the callback's body is evaluated every time the
observer detects a change, it will take the latest values for your
global variables.
BTW, this is based on 1.5 RC2.
--
Christophe Porteneuve a.k.a. TDD
"[They] did not know it was impossible, so they did it." --Mark Twain
Email: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---