让我们说我只想更改包含"博客"在它们中绿色或蓝色。请参阅我在jsfiddle中的示例。有没有办法根据内容改变bootstrap-table的行颜色? :P
请参阅jsfiddle
上的此示例
function rowStyle(row, index) {
var classes = ['active', 'success', 'info', 'warning', 'danger'];
if (index % 2 === 0 && index / 2 < classes.length) {
return {
classes: classes[index / 2]
};
}
return {};
}
&#13;
<table data-toggle="table"
data-url="/gh/get/response.json/wenzhixin/bootstrap-table/tree/master/docs/data/data1/"
data-row-style="rowStyle">
<thead>
<tr>
<th data-field="name">Name</th>
<th data-field="stargazers_count">Stars</th>
<th data-field="forks_count">Forks</th>
<th data-field="description">Description</th>
</tr>
</thead>
</table>
&#13;
答案 0 :(得分:2)
试试这个:
function rowStyle(row, index) {
const obj = {};
if (Object.keys(row).map(key => row[key]).some(value => String(value).includes('blog'))) {
obj.css = {'background-color': 'blue'};
}
var classes = ['active', 'success', 'info', 'warning', 'danger'];
if (index % 2 === 0 && index / 2 < classes.length) {
return Object.assign({}, obj, {classes: classes[index / 2]});
}
return obj;
}