我正在使用 Backbone 渲染一个方形瓷砖元素,在该元素中设置高度,然后动态设置宽度以匹配高度。但是,当尝试获取元素高度时,我被0退回了。
这是我的代码:
var app = app || {};
app.ClassModelView = Backbone.View.extend({
    className: 'tile',
    template: _.template('<%= name %>'),
    render: function() {
        var dim = 'calc(' + parseInt(100 / app.global.rows) + '% - ' + app.global.margin * (app.global.rows + 1) + 'px)'; //e.g. "30% - 20px"
        this.$el.append(this.template(this.model.attributes)).css({
            margin: app.global.margin + 'px',
            height: dim,
        }).css({
            width: this.$el.height() + 'px',
        });
        return this;
    }
})
如何将宽度设置$el为高度?我不确定我是否在语法上做错了什么,或者是否是我使用 Backbone 的方式导致了我的问题。