如何根据内容更改 bootstrap-table 行背景

How to change bootstrap-tabe row background depending on its content

假设我只想将其中包含单词 "Blog" 的行更改为绿色或蓝色。请参阅我在 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 {};
}
<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>

试试这个:

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;
}

updated JS Fiddle