【发布时间】:2017-05-31 02:08:21
【问题描述】:
尝试学习和理解克隆 html。所以我有一些 HTML,我从我创建的 json 测试提要中获取假期......基本......有一个日期和假期名称。
<table id="holidayTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="holidayDateHead">Holiday Date</th>
<th class="holidayNameHead">Holiday Name</th>
</tr>
</thead>
<tbody>
<tr id="emptyRow" class="tableRow">
<td class="holidayDate"></td>
<td class="holidayName"></td>
</tr>
</tbody>
</table>
我正在做一个 ajax 来获取 json 并使用它来完成它。
var holidayCount = 0; //Count of Items.
$(HolidayData).each(function(index, Holidays) {
var date = Holidays.holidayDate.replace(/(\d{4})-(\d{2})-(\d{2})(.*)/g, '$2/$3/$1');
var templateClone = $("#emptyRow .tableRow").clone()[0];
$(".holidayDate", templateClone).text(date);
$(".holidayName", templateClone).text(Holidays.name);
$("#holidayTable").append(templateClone);
holidayCount++;
});
但是这似乎不能正常工作,不知道为什么.....我可以控制台记录计数,我得到 10....这是我放入 json 中的假期数....但是它只在网页中显示 1。我在控制台中没有看到任何错误......所以没有什么能让我知道它为什么不工作。
任何人都可以对此有所了解以帮助我更好地理解这一点吗?
【问题讨论】: