I'm currently programming the web interface for a mvc web application and I need to get the models which have their checkbox checked.
At the moment this is the template i use to generate a single table row:
<td><span class="userintern"><%= intern %></span></td>
<td><span class="username"><%= name %></span></td>
<td><input id="add" class="add" type="checkbox" ></td>
This is the code for the view of the table row:
var UserView = Backbone.View.extend({
tagName: 'tr',
template: _.template(messageuser),
initialize: function () {
},
events: {
'click .add': 'add'
},
render: function () {
this.$el.html(this.template(this.model.attributes));
$('.add').prop('checked', false);
return this;
},
add: function () {
console.log($('.add').prop('checked'));
if($('.add').prop('checked'))
common.vent.trigger('messageView:add_user', { model: this.model });
else
common.vent.trigger('messageView:remove_user', { model: this.model });
}
});
return UserView;
My problem is, the first checkbox works perfectly fine, gives me true/false based on the status of the checkbox. Checkbox 2 -> ... always return false. I'm suspecting this is because i try to access the $('.add') with jquery which is the same for every checkbox, but how can I do this another way?
Aucun commentaire:
Enregistrer un commentaire