我试着根据“状态”给行上色,可以是红色/绿色。
使用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
最佳答案
看看文档的这一点: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');
}
});
}