bpickens-53BQRuF0lHYybS5Ee8rs3A@public.gmane.org
2008-May-19 19:42 UTC
up/down/delete functions for list items, problem with bound parameters
Hi all, I am dynamically creating an item list with div containers. Because of this dynamic nature, I am using the element.observe method along with the bindAsEventListener() function to bind its execution to within the object that creates the div in the first place. The problem is that the POS argument I am passing along with it is forever being bound to that element. This is causing a problem when I create the functions for ordering the list (up/down). I can reorder them, but the id stays with that element so that clicking on the up button for one element causes a different element to move. Here is my stripped down code for your viewing pleasure. // FEATUREDCONTENT OBJECT featuredcontent = Class.create({ initialize: function(name) { this.name = name; this.place = -1; this.FCArray = new Array(0); }, addElement: function(id,headline) { upf = (function (pos) { // Create div -> link -> img upLink.observe(''click'',this.upArticle.bindAsEventListener(this,pos)); return upLink; }).bind(pos); div.appendChild(upf(div.id)); }, upArticle: function(pos) { var before = this.FCArray[pos-1]; this.FCArray.splice(pos-1,1); this.FCArray.splice(pos,0,before) var div = $(''selected'').childElements()[pos]; div.id = pos-1; var divBefore = div.previous().insert({before: div}); divBefore.id = pos; } )} The user selects from some articles, which populates a ''selected'' list. Each of these gets an up/down/delete function. So, again, the problem is that the POS argument is for ever bound to the created element. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- Using Prototype - Getting Javascript Error - "Object doesn't support this property or method"
- Boot package for R 1.3.0
- img element inside div not accessible with $$() or getElementsBySelector
- Lisp-stat and R? [was: Re: Status?]
- read.delim skips first column (why?)