Good day. Trying to figure out backbone.js. There is an example http://megakolyan.ru/backbone/first/ I want the click on the .edit element to trigger the editTask event, but for some reason it does not work.
1 answer
It's not good to do this kind of magic.
this.$el = $('#todo'); Fixed your code. Handler click method already add yourself.
var Person = Backbone.Model.extend({ defaults: { name: 'Dima', age: 23, occupation: 'web developer' } }); var PersonView = Backbone.View.extend({ tagName: 'li', template:_.template($('#person-id').html()), events: { 'click': 'onClick' }, initialize:function(){ this.render(); }, render:function(){ this.$el.html(this.template(this.model.toJSON())); $('#todo').html(this.$el); return this; }, onClick: function(e) { if (e && e.preventDefault) { e.preventDefault(); console.log('click'); } } }); var person = new Person(); var personView = new PersonView({ model: person }); - Thank you very much - I can't understand why everything is working now, after I rewrote the code - this. $ El = $ ('# todo'); - Kolyunya
|