【发布时间】:2017-10-09 18:01:19
【问题描述】:
我的表格设计如下:
<tr>
<th rowspan="6" scope="row">Payment History: <br><em>(Up to 25 months)</em></th>
<td colspan="3">
<table id="paymentHistory" cellspacing="1" summary="Payment History" class="table table-sm table-bordered" >
<thead class="thead-default">
<tr>
<th style="white-space: nowrap;"></th>
<th style="white-space: nowrap;">Jan</th>
<th style="white-space: nowrap;">Feb</th>
<th style="white-space: nowrap;">Mar</th>
<th style="white-space: nowrap;">Apr</th>
<th style="white-space: nowrap;">May</th>
<th style="white-space: nowrap;">Jun</th>
<th style="white-space: nowrap;">Jul</th>
<th style="white-space: nowrap;">Aug</th>
<th style="white-space: nowrap;">Sept</th>
<th style="white-space: nowrap;">Oct</th>
<th style="white-space: nowrap;">Nov</th>
<th style="white-space: nowrap;">Dec</th>
</tr>
{{#each PaymentProfile}}
<tr>
<th rowspan="2">{{@key}}</th>
</tr>
<!--<tr>-->
<!--{{#each this}}-->
<!--<th style="white-space: nowrap;">{{months @key}}</th>-->
<!--{{/each}}-->
<!--</tr>-->
<tr>
{{#each this}}
<td style="height: 42px;">{{hideEmptyData this}}</td>
{{/each}}
</tr>
{{/each}}
</thead>
</table>
</td>
</tr>
我有一些单元格对于某些行是空的。我从中渲染的 JSON 有一些空字段/元素,因此它们没有显示在表格上。我想隐藏那些空的单元格。
我必须编写 registerHelper 或 jquery 函数吗?我该怎么做?
$("#paymentHistory > tbody > tr").each(function() {
console.log("inside table");
$td=$(this).find('td');
if($td.text() === ''){
$(this).css("display", "none");
}
// $(this).parent().hide();
});
我正在尝试上面的代码。但我无法进入函数本身。 我无法在控制台中打印“内表”。 有人可以建议我做错什么吗?
所以我想做的是隐藏空的表格单元格。例如,在 2014 年,所有月份的元素都是空的,所以我不想显示 2014 年的行;而在 2015 年,应该只显示 JAN 到 AUG 的元素,因为其他元素是空的。
JSON数据如下:
"PaymentProfile":{
"2015":{
"1":"9",
"2":"-",
"3":"-",
"4":"-",
"5":"-",
"6":"9",
"7":"9",
"8":"B",
"9":" ",
"10":" ",
"11":" ",
"12":" "
},
"2014":{
"1":" ",
"2":" ",
"3":" ",
"4":" ",
"5":" ",
"6":" ",
"7":" ",
"8":" ",
"9":" ",
"10":" ",
"11":" ",
"12":" "
}
},
有人可以帮帮我吗? Output of the above code
【问题讨论】:
-
{{#if td}} <td> ... </td> {{/if}} -
@awd 事情是我不想显示整个 2014 行,因为所有月份都是空的。那我该怎么做呢?
-
我认为如果您提供数据示例会有所帮助。
-
@76484 你的意思是 JSON 数据??
-
我会在将数据传递给模板之前对其进行格式化。例如,删除没有月份值的年份。
标签: javascript jquery html templates handlebars.js