I am making a module for the Joomla! page of a client that uses Ajax to render different queries to the database. The result of these queries is that I regenerate the entire HTML code of the different DIVs. Within my jQuery Object I have a function named as cache()
that stores all objects that I need to attach them the different events. My problem is that every time I regenerate the HTML code from any of these divs, I have to rebuild all the objects, so I've created a new function recache()
to make this work more easy.
I guess this is not the best procedure.
Is there any way to keep alive these handlers without having to call this function cache()
each time, or is there any way to rebind dynamically this objects?
Thank you!
Here my code:
var Object = {
init: function() {
this.cache();
this.bindEvents();
return this;
},
cache: function() {
OBJECTS....
this.nameObject = $('#anchor');
etc..
},
recache: function() {
Objects to be recached as needed.
},
bindEvents: function() {
EVENTS attached to the objects.
this.nameObject.on( 'click', 'context', this.nameFunction );
},
nameFunction: function() {
#CODE....
}
}; //END Playlist (Object)
window.Object = Object.init();
I usually use on()
function instead of delegate()
, live()
or bind()
, butI'm not sure this is exactly my problem.
Thanks in advance!