Question

There is a 'View' in the model with the event click. After using the Quicksand effects plug-in for jQuery, the objects loose their event handlers. I have tried to add the listener for the event with standard methods in backbone.js:

events: {
    "click .objContact"    : "openChat"
}

and the same tools jQuery delegate:

var self=this; 
this.$el.delegate('.objContact','click', function(){
    self.openChat();
});

and live:

var self=this; 
this.$el.find('.objContact').live('click', function(){
    self.openChat();
});

but the click event disappears. What could be the problem? And how do I solve it?

UPD: Calling 'Quicksand' is in Backbone.Router (subject to change is obtained directly by means of jQuery, not Backbone), so changes are not handled in Backbone.View

UPD 2: The problem is solved in the following way - by moving the handling of the click event from the View-model to View-collection. And treated with live (did not work in on)

Was it helpful?

Solution

Do a call to delegateEvents() after the related DOM entries have changed or become overwritten. In a traditional Backbone app this is typically done in the render method, but you probably need for figure out when and where quicksand does it's magic (I do not know anything about it), and call delegateEvents that will reactivate the events for the current elements in the DOM.

OTHER TIPS

Simple Answer: instead of linking the function to the link with the classic ajax method that is

$('a.oldJqueryClass').click(function(){....

you need to make that function standalone, declaring a new function

function myfunction(params) {alert(params);}

than in the link you call that with the old school way:

<a href="#" class="oldJqueryClass" onclick="javascript:myfunction('My alert message')">Click here</a>

In this way the cloned element will contain itself the call to the function and you can forget about restoring the dom integrity broken by the cloning of quicksand.

I did it in my project, it works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top