Power BI 自定义视觉开发 - 无法为 div 设置高度

Power BI Custom Visual development - Cannot set height for div

我正在尝试为 Power BI 开发自定义视觉对象。 我有 div 元素和传单地图。当我不设置高度时,视觉是空的。我可以用 this.mapDiv.style.height="300px";

设置高度

但这是固定的。 如何通过视口动态设置高度?

这是我的代码

private mapDiv: HTMLElement;

    constructor(options: VisualConstructorOptions) {

        this.mapDiv = document.createElement("div");
        this.mapDiv.id = "mapid";   
        options.element.appendChild(this.mapDiv);

        var map = L.map('mapid');
            map.setView([48.14, 17.12], 13);

        L.tileLayer('https:....', {
                minZoom: 4,
                maxZoom: 18,
         }).addTo(map);

    }

    public update(options: VisualUpdateOptions) {
        // this.mapDiv.style.height = "300px"; WORKS
        this.mapDiv.style.height = options.viewport.height.toString(); // DOESNT WORKS !!!
    }

你能帮忙吗?

您需要将 "px" 追加回 options.viewport.height,因为它只是一个数字。

即你可以试试

this.mapDiv.style.height = options.viewport.height + "px";