0

I have a bootstrap-table which loads its data from a .json file. Everything works nicely but I am now trying to add a data-formatter="winLOSSFormatter"to one column and can't make that work.

Basically I am looking for it to be a simple if else statement that looks at the value and changes the color of the text for that field based on the value.

For example if the value includes the word "win," the text would be green.; the word "loss," the text would be red. Anything else the text would be standard black.

I believe this should be fairly simple to achieve with something along the lines of the script below but I can't seem to make it work.

Thanks!

function winLOSSFormatter(value) {
    if (value.indexof ('Win') > -1) {
                color = 'green';
                } else if (value.indexof('Loss') > -1 {
                'red';
                } else {
                 color = 'black';
                };
    return  '<div  style="color: ' + color + '">' + value.substring(1) + '</div>';
}
4

2 に答える 2

0

} else if (value.indexof('Loss') > -1 {関数の実行を妨げていた閉じられていないブラケットが ありました。以下は作業コードです。

function winLOSSFormatter(value) {
    if (value.match(/.*Win.*/ig)) {
                var color = 'green';
                } else if (value.match(/.*Loss.*/ig)) {
                'red';
                } else {
                 color = 'black';
                };
    return  '<div  style="color: ' + color + '">' + value + '</div>';
}

次のような値をどのように処理したいかわかりませんThisLossIsMyWinValue

于 2015-09-09T03:06:42.907 に答える
0
function winLOSSFormatter(value) {
var color = '#99C262';

if (value.indexOf('W') > -1) {
            color = 'green';
            } else if (value.indexOf('L') > -1) {
            color = 'red';
            } else {
             color = 'black';
            }
return  '<div  style="color: ' + color + '; font-weight: 700;">' + value.substring() + '</div>';
}
于 2015-09-09T02:05:37.050 に答える