我正在尝试根据“状态”对行进行着色,该状态可以是红色/绿色。 使用dynatable根据JSON数据生成表行。
问题在于每当我从dynatable调用以下代码时,它总是被dyntable.process();
覆盖$('#mytable tr td').each(function() {
if ($(this).text() == 'Red') {
$(this).closest('tr').css('background-color', '#f00');
}
});
我的index.php: http://pastie.org/10389654
我的index.js: http://pastie.org/10389656
答案 0 :(得分:0)
请看文档的这一点:Documentation - Event
可能使用dynatable:beforeUpdate
事件
这样的一些方法:
var dynatable = $('#mytable').dynatable({
dataset: {
ajax: true,
ajaxUrl: './api.php',
ajaxOnLoad: true,
records: []
},
params: {
records: 'data'
},
features: {
paginate: false,
sort: false,
pushState: false,
search: false,
recordCount: false,
perPageSelect: false
}
}).data('dynatable').bind('dynatable:afterProcess', changeColor);
然后你的功能
function changeColor() {
$('#mytable tr td').each(function() {
if ($(this).text() == 'Red') {
$(this).closest('tr').css('background-color', '#f00');
}
});
}