Ollie wrote:
> I ommited a few things such as recursion control and the url to update
> from. I apologise for that.
> The ommited aspects are of course important, but they are not the
> cause of my problem.
>
> update(['a','b','c'], 0);
>
> function update(values, index){
>
> if(values.length <= index) return;
>
> Ajax.Updater(values[index], SOME_URL, {onComplete:update(values,
> index+1)});
>
> }
Someone already answered this, but you need to use an anonymous function as the
value of onComplete. You are passing it the *return* value of the update()
function which means you're actually executing it before the previous run has
finished executing. And you need to use 'new' since you're creating a new
object.
function update(values, index){
if(values.length <= index) return;
new Ajax.Updater(values[index], SOME_URL, {
onComplete: function() { update(values,index+1)}
});
}
Now, when currying support makes it into prototype (1.5.2?) you can do something
like this:
function update(values, index){
if(values.length <= index) return;
new Ajax.Updater(values[index], SOME_URL, {
onComplete: update.given(values,index+1)
});
}
--
Michael Peters
Developer
Plus Three, LP
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---