efk*_*kan 3 javascript jquery footable
我正在尝试添加来自Ajax的记录作为响应.我的代码如下;
Ps:我可以alert正确地看到命令的ajax响应.
<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>
Run Code Online (Sandbox Code Playgroud)
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"}];
Run Code Online (Sandbox Code Playgroud)
$.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.");
}
});
Run Code Online (Sandbox Code Playgroud)
在将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.");
}
});
Run Code Online (Sandbox Code Playgroud)
然后使用footable_initialize 触发器而不是footable_redraw触发器.
这是一个实际的jsfiddle.
| 归档时间: |
|
| 查看次数: |
12012 次 |
| 最近记录: |