admin管理员组文章数量:1334342
I'm trying to hook up a checkbox to my View, but as soon as I tick it, it stays checked, even when I click it again?
Here's part of the View:
views.PaginatedView = Backbone.View.extend({
events: {
'click inputpletedEnquiries': 'filterCompletedEnquiries'
},
filterCompletedEnquiries: function (e) {
return e.currentTarget.checked;
}
});
Heres the template:
<label>Show Completed: <input type="checkbox" class="pletedEnquiries" /></label>
I've no idea what I'm doing wrong here?
Edit
Here is a Jsfiddle of the problem: /
I'm trying to hook up a checkbox to my View, but as soon as I tick it, it stays checked, even when I click it again?
Here's part of the View:
views.PaginatedView = Backbone.View.extend({
events: {
'click input.pletedEnquiries': 'filterCompletedEnquiries'
},
filterCompletedEnquiries: function (e) {
return e.currentTarget.checked;
}
});
Heres the template:
<label>Show Completed: <input type="checkbox" class="pletedEnquiries" /></label>
I've no idea what I'm doing wrong here?
Edit
Here is a Jsfiddle of the problem: http://jsfiddle/9cvVv/167/
Share Improve this question edited Aug 30, 2012 at 11:57 Derick Bailey 72.9k23 gold badges212 silver badges221 bronze badges asked Aug 30, 2012 at 11:14 CallumVassCallumVass 11.5k27 gold badges88 silver badges155 bronze badges 2- Something else is happening due everything looks right for me. Can you reproduce the issue in a jsFiddle? – fguillen Commented Aug 30, 2012 at 11:20
- jsfiddle/9cvVv/167 – CallumVass Commented Aug 30, 2012 at 11:40
1 Answer
Reset to default 6The problem is returning e.currentTarget.checked
from your event handler. Returning true
or false
from this handler will check or uncheck the box for you
filterCompletedEnquiries: function(e) {
//return e.currentTarget.checked;
},
ment out that return statement, and it works fine. You can still grab the info, but don't return anything from the method.
filterCompletedEnquiries: function(e) {
var isChecked = e.currentTarget.checked;
// do stuff here, based on it being checked or not
},
Edit
Here's an example, based on the conversation in the ments:
views.PaginatedView = Backbone.View.extend({
events: {
'click input.pletedEnquiries': 'pletedEnquiriesClicked'
},
// this is explicitly an event handler, and that's all it should be used for
pletedEnquiriesClicked: function(e){
this.showCompletedEnquiries = e.currentTarget.checked;
},
doSomething Else: function (e) {
// now that we need to know, we can just check that attribute
if (this.showCompletedEnquiries){
// do something here
}
}
});
This is just one of many options you have, for making this work the way you want.
本文标签: javascriptBackboneCheckbox stays checkedStack Overflow
版权声明:本文标题:javascript - Backbone - Checkbox stays checked? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742247120a2440059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论