我正在尝试添加来自Ajax的记录作为响应。我的代码如下;
Ps:我可以正确地看到alert命令的ajax响应。
Html代码
<table id="seller-table" class="table" data-filter="#filter" data-page-size="5">
<thead>
<tr>
<th data-toggle="true">ID</th>
<th>Date</th>
</tr>
</thead>
<tbody>
</tbody>
</table>数据格式为json
var data = [{"id": 10, "date": "Mon Aug 04 2014 17:00:00"},
{"id": 11, "date": "Tue Aug 05 2014 17:00:00"},
{"id": 12, "date": "Wed Aug 06 2014 17:00:00"}];jQuery码
$.ajax({
url : '/bid/find/',
data: { },
success : function(data) {
$('table tbody').append(data);
$('table').trigger('footable_redraw');
},
error : function(xhr, statusText, error) {
alert("Error! Could not retrieve the data.");
}
});发布于 2014-08-07 19:44:50
AJAX调用返回的对象数组必须转换为HTML元素,然后才能将它们添加到表中:
$('table').footable();
function create_seller_table_row (item) {
var row = $('<tr><td>' + item.id + '</td><td>' + item.date + '</td></tr>');
return row;
}
$.ajax({
url : '/bid/find/',
data: { },
success : function(data) {
$.each(data, function(index, item){
var row = create_seller_table_row(item);
$('table tbody').append(row);
});
$('table').trigger('footable_initialize');
},
error : function(xhr, statusText, error) {
alert("Error! Could not retrieve the data.");
}
});然后使用footable_initialize触发器而不是footable_redraw触发器。
以下是它的实际应用的jsfiddle。
https://stackoverflow.com/questions/25166373
复制相似问题