Backbone.js event trigger in render ()

I am attached to some events in renderthe backbone.js function, more specifically a click, however I cannot get it to work.

I have a similar (but very simplified) setup:

App.ProductView = Backbone.View.extend({

className: 'title_products_tab',
el: $('.title_products_tab'),

events: {
    'click .product_list .edit_product' : 'edit',

In the events section of my spine. Inside the render function, I want to trigger an event .edit_product click:

render: function(){
        console.log($._data( $('.title_products_tab .product_list .edit_product')[0], "events" ));
        $('.title_products_tab .product_list .edit_product').trigger('click');

Which does not work _datafor the undefined element, however, I know that this event works because the rest of my view functions accordingly. I just can't fire events in renderor anywhere else on startup.

I thought:

this.trigger('click .product_list .edit_product');

Will work, again, no luck.

I also heard about bindAll, but I heard that this is not a good idea.

, , , ?

+5
1

, (: ):

var View = Backbone.View = function(options) {
  this.cid = _.uniqueId('view');
  this._configure(options || {});
  this._ensureElement();
  this.initialize.apply(this, arguments);
  this.delegateEvents();
};

. , initialize, render. .

( , delegateEvents, , )

+2

All Articles