How do I add preventDefault() to the <button> in the event? What I have below is not working .. thanks
var View = Backbone.View.extend({
initialize: function () {
//console.log('initializing ' + this.options.blankOption);
this.template = $('#list-template').children();
},
el: '#container',
events: {
'click button' : 'render'
},
render: function(){
this.events.preventDefault(); // not working ????
var data = this.model.get('data');
$.each(data,function (i,v) {
console.log(data.text + " " + data.href);
});
}
});
this.events is not a event object. so it not work
try this:
render: function(event){
event && event.preventDefault();
var data = this.model.get('data');
$.each(data,function (i,v) {
console.log(data.text + " " + data.href);
});
}
Receive the event object as an argument
render: function(evt){
evt.preventDefault();
var data = this.model.get('data');
$.each(data,function (i,v) {
console.log(data.text + " " + data.href);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With