If #bind or #curry somehow don't satisfy your needs, there's always a
plain old function wrapping (which simply stores "id" in its own
closure):
...
.onclick = (function(id){
return function(){ fc.selectArticle(id, ret.headline[i]) }
})(id);
...
- kangax
On May 15, 5:57 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Hi all,
> I am having trouble with my variable assignments always becoming the
> last variable inside my loop.
>
> var populateAvailableContent = Class.create(methodCall, {
> initialize: function($super, name, message) {
> $super(name,'getAllContent','Loading...')
> },
> result: function(ret) {
> var div = $('articles');
> div.innerHTML = null;
> var rowCount = ret.getRowCount();
> for (i=0;i<rowCount;i++) {
> var item =
> document.createElement('div');
> var id = ret.id[i]
> var headline = ret.headline[i];
> var html = headline + "<hr />";
> item.id = "item";
> item.onclick =
> function(){fc.selectArticle(id,headline);};
> item.innerHTML = html;
> div.appendChild(item);
> }
> }
> })
>
> In this scenario, id and headline are always becomes the last value in
> the loop and that is what is passed in the fc.selectArticle()
> function. I've tried a few different possible solutions I've found on
> the web, but none seemed to work. I decided to try and give the bind()
> function a go around but I can't seem to figure out how to use it in
> my situation.
>
> Any help would be greatly appreciated.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---