javascript - CSS 中的表格尺寸在 HTML 中不起作用

标签 javascript html css html-table

我无法按预期以表格格式获取数据。

myList = '[{"date":"2020-04-05 18:26:01", "symptom":{"chest_pain":{"type":"Mild"},"cough":{"frequency":"5 to 15 times an hour","type":"With Flum"}}},{"date":"2020-04-06 14:57:11", "symptom":{"fever":{"temperature":"98"},"digestion_problem":"Yes"}},{"date":"2020-04-13 04:04:25", "symptom":{"cough":{"frequency":"Less than 5 times an hour","type":"Dry"},"breathing":{"severity":"6"}}}]';

function buildHtmlTable(selector) {
    var columns = addAllColumnHeaders(myList, selector);

    for (var i = 0; i < myList.length; i++) {
        var row$ = $('<tr/>');
        for (var colIndex = 0; colIndex < columns.length; colIndex++) {

            var cellValue = getCellValue(myList[i], columns[colIndex]);
            if (cellValue == null)
                cellValue = "";
            row$.append($('<td/>').html(cellValue));
        }
        $(selector).append(row$);


    }
    $('th').each(function() {
        var text = $(this).text();
        $(this).text(text.replace(/symptom/g, "")); 
        text = $(this).text();
        $(this).text(text.replace(/-/g, " ")); 
        text = $(this).text();
        $(this).text(text.replace(/_/g, " ")); 
        text = $(this).text();
        $(this).text(capitalizeFirstLetter(text)); 
    });
}

function capitalizeFirstLetter(str) {
    return str.replace(/\w\S*/g, function(txt){
        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
    });
  }

  console.log(capitalizeFirstLetter('foo')); // Foo


function addAllColumnHeaders(myList, selector) {
    var columnSet = [];
    var headerTr$ = $('<tr/>');

    for (var i = 0; i < myList.length; i++) {
        var rowHash = myList[i];

        recursiveHeaderCheck(rowHash, selector, "", columnSet, headerTr$);
    }
    $(selector).prepend("<thead>");
    $(selector).append(headerTr$);
    $(selector).append("</thead>");

    return columnSet;
}
#symptom_table{
  width: 85vw !important;
  height: 50vh !important;
}

#excelDataTable  {
  width: 85vw !important;
  height: 50vh !important; 
} 
<div id="symptom_table"> 
     <table class="fl-table" id="excelDataTable" border="none"> </table>
  </div>

我正在尝试以 HTML 形式显示从数据库中获取的表格。

但是,当我加载页面并检查时,我看不到该表格。 我发现我的尺寸不匹配。数据表也包含数据。

不确定我缺少什么

编辑1: 将 - 更改为 _ 后,.到 #,wh 到 vh。 症状表 enter image description here excel数据表 enter image description here

编辑2: 我可以在控制台中看到来自 js 的数据: enter image description here

最佳答案

您的 CSS 与表的 ID 不匹配:.symptom-table 类不适用于 ID 为 symptom_table 的 div(注意 -) > 和 _)。 我认为您需要将 .symptom-table 选择器更改为 #symptom_table,即通过 ID 和正确的拼写来选择表。

此外,将单位从 wh 修复为 vh

关于javascript - CSS 中的表格尺寸在 HTML 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61192123/

相关文章:

javascript - 如何隐藏来自 CMS 页面的元素

javascript - JSON.stringify 看似缩写值

javascript - 如何通过NodeJS连接远程数据库

jquery - DIV 中的垂直对齐图像

php - 我的 WP 博客中的图片在其他网站上不显示

javascript - 在 javascript click() 中获取 php 变量?

javascript - 如何使滚动更平滑(不是 anchor 链接,只是一般滚动)

javascript - 带有拖放功能的 JQuery Scheduler

jquery - 为什么不能覆盖 Bootstrap 按钮上的 CSS 背景颜色?

html - 悬停时使图像尺寸变大