我有一个提供SSE资源的RESTful服务。我每3秒更新一次HTML表。我在上面用了dynatable。当添加新行时,SSE会通知客户端,因此会更新该表。
我正在用这些新行更新一个表:
$('#mytable tr:first').after(newRows);但是dynatable并没有应用于这些新的行。我读到"Dynatable不会更新DOM中的表,直到我们调用process()“。因此,我尝试在插入新行之后调用dynatable.process(),但它不起作用。
这是我的桌子。看看前两行。未应用样式、斑纹和格式化程序。

下面是我的javascript代码:
if(typeof(EventSource)!=="undefined") {
var source = new EventSource("SOME_URL/sse");
source.onmessage = function(e) {
if(e.data) {
/* In the CrunchifyTableView method, I'm putting the json result indo table
rows. I'm doing this because if I pass json directly to dynatable, I'm not
able to styling some columns, like "Alerta" column (see image).*/
var newRows = CrunchifyTableView(e.data, "registers");
$('#registers tr:first').after(newRows);
// TODO
// Update dynatable
applyDynaTable(); // I tried reload the dynatable but it's not working
}
};
}
else {
// No support
}
function applyDynatable() {
$('#registers').dynatable({
features: {
paginate: true,
search: false,
recordCount: true,
perPageSelect: false
},
writers: {
'dataEhora': function(record) {
return formatDate(record.dataEhora); // Date formater
}
}
});}
发布于 2015-08-15 04:23:28
您的applyDynatable函数应该如下所示:
function applyDynatable() {
var dynatable = $('#registers').dynatable({
features: {
paginate: true,
search: false,
recordCount: true,
perPageSelect: false
},
writers: {
'dataEhora': function(record) {
return formatDate(record.dataEhora); // Date formater
}
}).data("dynatable");
dynatable.process();
} https://stackoverflow.com/questions/32017645
复制相似问题