【发布时间】:2020-04-14 01:07:07
【问题描述】:
我无法按预期以表格格式获取我的数据。
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 格式显示从我的数据库中获取的表格。
但是,当我加载页面并检查时,我看不到表格。 我发现我的尺寸不匹配。数据表也包含数据。
不知道我错过了什么
【问题讨论】:
-
50vh,不是50wh。 -
您有一个带有 id 症状表 的表 - 但您在 CSS 中使用了 class 症状表。下划线 vs hive 和 id vs class。
-
@Azametzin 50vh 已经完成,没有运气。
-
@Daniel,我改变了 _ 改变了,没有改变我仍然看不到表格
-
我建议你在 codepen 或 jsfiddle 上准备一个运行版本的代码。更容易理解您的问题
标签: javascript html css html-table