div 自动高度对于内容来说太小

发布于 2025-01-10 00:00:40 字数 834 浏览 0 评论 0原文

我遇到的情况是,我有一个通常在 jsp 中显示的报告,现在我有一个打印,其中需要多次包含所述页面的多个实例,所以这是一个组合报告之类的事情。为了避免使用相同的键向模型添加值时出现的问题,我们想出了这种包含 jsp 的方法。

<c:forEach var="prodTest" items="${listProductionTest}">
<div style="display:block" id="chargeReport${prodTest.report.recId}">
</div>
<script type="text/javascript">
    $.get("ChargeReportContent?recId=${prodTest.report.recId}", function( data ) {
        $("#chargeReport${prodTest.report.recId}").html(data);
    });
</script>

ChargeReportContent 是一个返回带有值的 jsp 的端点。它正确检索数据,但是 div 高度完全错误,导致两个报告重叠。看来自动高度给了自己足够的高度,只包含报告的第一部分。

显示块似乎不起作用

显示块似乎不起作用。这些报告的大小应约为 1500 像素,但将高度设置为固定值并不是真正的选择,因为大小可能会根据报告或更新而变化。

请帮忙!

I have a situation where I have a report that is normally displayed in a jsp, and now I have a print where those multiple instances of said page needs to be included multiple times, so this is a combined report kind of thing. To circumvent issues that would arise from adding values to the model with the same key we came up with this way to include the jsp.

<c:forEach var="prodTest" items="${listProductionTest}">
<div style="display:block" id="chargeReport${prodTest.report.recId}">
</div>
<script type="text/javascript">
    $.get("ChargeReportContent?recId=${prodTest.report.recId}", function( data ) {
        $("#chargeReport${prodTest.report.recId}").html(data);
    });
</script>

ChargeReportContent is an endpoint that returns the jsp with the values. It retrieves data correctly however the divs height is all wrong causing the both reports to overlap. It seems auto height gives itself enough height to only include the first part of the report.

display block doesnt seem to work

display block doesnt seem to work. These reports should each have size of around 1500px but putting the height as a fixed value is not really an option as the size can change depending on the report or updates.

Plz help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙气飘飘 2025-01-17 00:00:40

div 中元素的位置是什么?
确保它们不是固定的、绝对的或浮动设置的。
div默认设置为display block,你可以尝试将其设置为flex

what's the position of the elements inside the div?
Make sure they are not fixed, absolute or have float set.
Divs are set to display block by default, you might try to set it to flex

带上头具痛哭 2025-01-17 00:00:40

有同事提出这是因为html是通过编程方式填充的,尺寸不准确。我们从来没有找到一个干净的方法来解决这个问题,但我们想出的最好的办法是自己计算所需的高度,然后设置它。例如
标题始终为 92px,配方始终为 256px,Reportlines 大小= 42+(21(materials+1)),注释部分如果没有注释则为 23px,如果有注释则为 42 等。
如果在 JSP 中我们无法轻松检索多个警报,我们会创建一个不可见的输入来存储值,并由模型添加

<input id="alarmCounter${report.recId}" style="display: none" value="${alarmCount}"></input>

,然后我们检索 val 以在计算中使用它。
找到总数后,我们只需将其设置在获取包含页面的 get 中
$.get("ChargeReport?recId=${prodTest.report.recId}", function( data ) {

        $("#chargeReport${prodTest.report.recId}").html(data);
        let alarmCount = 0;
        alarmCount =parseInt($('#alarmCounter${prodTest.report.recId}').val());
        var chartsize = 400*($('#chartExists${prodTest.report.recId}').val() == 'true' ? 1 : 0)
        var pixelsNeeded= 92 + 256 + 205
        + 42+ 21*(${fn:length(prodTest.report.reportLines)}+1)
        + 21*(alarmCount+2) 
        +19+24*${!empty prodTest.report.comment}
        + chartsize + 51 
        +50;

        $('#chargeReport${prodTest.report.recId}').css("height",pixelsNeeded+"px");

A colleague suggested that this is because the html was filled programmatically, the size was not accurate. We never figured out a clean way to fix this, but the best we came up with is to calculate the needed height ourselves and then set it. For example
the title is always 92px, recipe is always 256px, Reportlines size= 42+(21(materials+1)), notes part is 23px if there are no notes, 42 if there is a note, etc.
if in the JSP we could not easily retrieve a number of Alarms we made an invisible input to store the value and is added by the model like

<input id="alarmCounter${report.recId}" style="display: none" value="${alarmCount}"></input>

and then we retrieve the val to use it in the calculation.
After we find the total we just set it in the get that gets the included page
$.get("ChargeReport?recId=${prodTest.report.recId}", function( data ) {

        $("#chargeReport${prodTest.report.recId}").html(data);
        let alarmCount = 0;
        alarmCount =parseInt($('#alarmCounter${prodTest.report.recId}').val());
        var chartsize = 400*($('#chartExists${prodTest.report.recId}').val() == 'true' ? 1 : 0)
        var pixelsNeeded= 92 + 256 + 205
        + 42+ 21*(${fn:length(prodTest.report.reportLines)}+1)
        + 21*(alarmCount+2) 
        +19+24*${!empty prodTest.report.comment}
        + chartsize + 51 
        +50;

        $('#chargeReport${prodTest.report.recId}').css("height",pixelsNeeded+"px");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文