javascript - Click on "this" in a backbone view -


i newbie backbone , have little problem events system.

i have view represents li element, , want when click on it.

here code :

var indicatorview = backbone.view.extend({   tagname: 'li',   classname: 'indicator',   initialize: function(options){     _.extend(this, _.pick(options, "controller"));     this.model.on('change', this.render, this);     var self=this ;     this.$el.on("click", function(){       alert(self.model.get('name'));     })   },   render: function(){     this.$el.html(this.model.get('name'));     return this; // enable chained calls   } }); 

for moment, works, using jquery events. how can same thing backbone events ? answers :)

use empty selector bind event view el:

var indicatorview = backbone.view.extend({     tagname: 'li',     classname: 'indicator',      events: {         'click': function() {             alert(this.model.get('name'));         }     },      initialize: function(options){         _.extend(this, _.pick(options, "controller"));          // listento recommended on over         // http://backbonejs.org/#events-listento         this.listento(this.model, 'change', this.render);    },    render: function(){        this.$el.html(this.model.get('name'));        return this; // enable chained calls    } }); 

see http://backbonejs.org/#view-delegateevents more info


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -