admin管理员组文章数量:1391756
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);
});
}
});
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);
});
}
});
Share
Improve this question
asked Feb 25, 2013 at 9:11
Hello-WorldHello-World
9,55524 gold badges90 silver badges157 bronze badges
3 Answers
Reset to default 5this.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);
});
}
You can re-activate the actions by adding
this.delegateEvents(); // Re-activates the events for all the buttons
If you add it to the render function of a backbone js view, then you can use event.preventDefault() as required.
本文标签: javascripthow do I add preventDefault() backbonejsStack Overflow
版权声明:本文标题:javascript - how do I add preventDefault() backbone.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744766514a2624074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论