In the render function of my backbone app, I want to fill the rest of the table with empty rows for the alternating row look, but I dont know how many rows to add. I tried this.el.clientHeight
, $(this.el).height()
, and all other permutations of such functions to have them all return 0. Does anyone know how to do this? I also dont want to add too many in order not to introduce a scroll bar.
var bar = Backbone.View.extend({
initialize: function(){
_.bindAll(this, "render");
},
render: function(){
var html = "<h1>Hi!</h1>";
$(this.el).html(html);
var myWidth = this.el.width();
alert(myWidth);
return this;
}
});
var foo = Backbone.View.extend({
el: $('#myElement'),
initialize: function(){
_.bindAll(this, "render");
this.subview = new bar();
},
render: function(){
$(this.el).append(this.subview.render().el);
return this;
}
});
Solution for those stuck with the same problem as I had: You have to wait for the elements to be fully attached to the dom in order to get height/width info. In order to resolve this I added a postrender call after the render is fully done which went back and handled any small details.