$("#clckjson").click(function() {
$(document).ready(function() {
$.getJSON("fuelj.json", function(data) {
$(data).each(function(i, item) {
console.log(item.stationID);
var $table = $('<table>');
$table.append("<thead>").children("thead")
.append("<tr/>").children("tr").append("<th>StationID</th><th>Distance</th><th>Address</th><th>H24</th><th>Phones</th><th>FuelTypeID</th><th>FuelPrice</th><th>PriceTimestamp</th><th>FuelName</th>");
var $tbody = $table.append("<tbody/>").children("tbody");
$tbody.append("<tr/>").children("tr:last")
.append("<td>").append(item.stationID)
.append("<td>").append(item.distance)
.append("<td>").append(item.address)
.append("<td>").append(item.value)
.append("<td>").append(item.phone)
.append("<td>").append(item.fuelTypeID)
.append("<td>").append(item.price)
.append("<td>").append(item.priceTimeStamp)
.append("<td>").append(item.fuel);
$table.appendTo('#stationtb');
});
});
});
});
У меня есть html-страница с div кнопкой и таблицей внутри, а с помощью jQuery я хочу динамически добавлять ячейки с объектами JSON в таблицу, и когда я нажимаю кнопку, все отображается.Проблема в том, что когда я нажимаю кнопку, таблица отображается очень хорошо, но элементы, которые я пытаюсь добавить, не отображаются вообще, а console.log
показывает undefined
.Можно мне помочь?