On Nov 17, 10:17 pm, phegaro <[email protected]> wrote:
> Delegation sounds like a good model for doing this although if i want
> to pass parameters that are custom to each node like which id did it
> click on then i assume i have store it as a property on the node and
> pass arguments to the delgated function?
>
> In the above example if doIt took a paramter of the id to work on,
>
> doIt(id)  {
> // do something to the object with id X
> ...
>
> }
>
> Then with the delegation model i would have to retreive the node using
> findelement and then have an attribute on the node that held the id?
> Is that right?
>

Yes, clearly; if the processing is different for different element
then a delegation model requires you to determine which element you
are processing and choose your processing accordingly.

If each item is distinct, give them all an HTML 'id', and just use
that:

function doIt(e) {
var element = e.findElement('.item');
 var id = element.id;

If there are classes of them, it's easiest to use CSS classes:

<span class='item click_class_1'> ...

function doIt(e) {
 var element = e.findElement('.item');
 var class_1 = element.hasClassName('click_class_1');

or more generally

function doIt(e) {
  var element = e.findElement('.item');
  if (var matches = element.className.match(/click_class_(\n+)/) {
    var clickclass = matches[1]);

--

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=.


Reply via email to