Hi all,
  I'm building an AJAX list controller, and I'm having a few issues.
I'm new to Prototype and anything worth doing in javascript as well.
Please bear with me if my questions are obvious.

Basically, for each list item, I want to attach a function call to an
onclick event.  Generally this is easy if you use inline functions.
However, I have a lot of logic to perform, and I'd prefer to
encapsulate all of the functionality within a class to keep my code
cleaner.

I create the Element objects in the DOM dynamically from a JSON
response and attache the onclick event. However, when on onclick event
is fired and the "apply" function is executed, the "this" pointer does
not exist within the scope of the apply function.  Given that I set up
things in the constructor, how can I access these properties within an
event and keep my code in a class?

var MessagePagingConroller = Class.create({

loadPage: function(){
....
  var parentDiv = new Element('div', {'class':'message'});
  var markRead = new Element('a', {'href':'#});
  markRead.insert('mark as read');
....
}
});


new MarkReadHandler(markRead, message.Id, parentDiv);


var MarkReadHandler = Class.create({
   initialize: function(element, messageId, messageDiv){
     this.url = '/MessageCenter.mvc/MarkAsRead?id='+messageId;
     this.flashElement = messageDiv;

     element.onclick = this.apply;
   }

   apply: function(event){
     var ajaxRequest = new Ajax.Request(this.url, { synchronous:
true});

     //TODO handle error
     if(ajaxRequest.transport != 200){
        return;
      }

     event.element.hide();
     new Effect.Highlight(this.flashElement);
.. Do shifting etc

   }

});




--~--~---------~--~----~------------~-------~--~----~
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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to