
Untitled
By: a guest on
Aug 10th, 2012 | syntax:
None | size: 0.83 KB | hits: 4 | expires: Never
$(this.el).find() works in event handler, not in initialize function (backbone.js)
PhotoListItemView = Backbone.View.extend({
tagNAme: 'div',
className: 'photo_box',
events: {
'click': 'setStateLike'
},
initialize: function() {
this.setStateLike();
},
render: function() {
$(this.el).html( this.template( this.model.toJSON() ) );
return this;
},
setStateLike: function() {
console.log( $(this.el).find('#like') ); // returns []
if(this.model.get('is_liked')) {
console.log( $(this.el) ); // returns correctly
console.log( $(this.el).find('#like') ); // returns []
// Change icon to Active state
$(this.el).find('#like.photo_btn').addClass('photo_btn_active').attr('id', 'unlike');
}
}
});