我怎样才能获得尺寸(高/宽)的骨干浏览信息? [英] How can I get size (height/width) information in Backbone Views?

查看:89
本文介绍了我怎样才能获得尺寸(高/宽)的骨干浏览信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的骨干应用程序的渲染功能,我想填补的交替行看空行的表的其余部分,但我不知道有多少行补充。我试图 this.el.clientHeight $(this.el).height(),和所有其他的排列这些功能将它们全部返回0。有谁知道如何做到这一点?我也不用想添加太多,为了不引入一个滚动条。

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;
    }

});




解决方案为那些坚持同样的问题,因为我有:你必须等待元素,以获得高度/宽度信息完全附加到DOM。为了解决这个我添加了一个postrender调用后呈现完全做到这回去处理的任何小细节。

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.

推荐答案

尝试获得高度您附加后,(所以在富,而不是巴)。

Try getting the height after you attach it, (so in "foo" as opposed to "bar").

例如在富

    render: function(){

    $(this.el).append(this.subview.render().el);
    alert($(this.subview.el).height());
    return this;
}

这篇关于我怎样才能获得尺寸(高/宽)的骨干浏览信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆