我正在尝试根据“状态”(可以是红色/绿色)对行进行着色。使用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
发布于 2015-09-01 13:41:27
看看docs的这一点:文件-活动
并使用可能的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');
}
});
}https://stackoverflow.com/questions/32333053
复制相似问题