Javascript 根据单元格的值更改表的行类

Javascript 根据单元格的值更改表的行类,javascript,jquery,twitter-bootstrap-3,bootstrap-modal,Javascript,Jquery,Twitter Bootstrap 3,Bootstrap Modal,是否可以根据数据单元的值更改行类(使用引导)? 大概是这样的: (这里我将类硬编码到行中) 这是一段代码 onEachFeature: function (feature, layer) { if (feature.properties) { var content = "<table class='table table-striped table-bordered table-condensed'>" + "<tr><th>Šifr

是否可以根据数据单元的值更改行类(使用引导)? 大概是这样的: (这里我将类硬编码到行中)

这是一段代码

 onEachFeature: function (feature, layer) {
    if (feature.properties) {
      var content = "<table class='table table-striped table-bordered table-condensed'>" + "<tr><th>Šifra trafostanice</th><td>" + feature.properties.ts_sifra + 
      "</td></tr>" + "<tr><th>Name</th><td>" + feature.properties.ts_naziv + "</td></tr>" +  
      "<tr><th>Code</th><td>" + feature.properties.sifra_lampe + "</td></tr>" +
      "<tr><th>Power</th><td>" + feature.properties.tip_lampe + "</td></tr>" +
      "<tr><th>Pole type</th><td>" + feature.properties.vrsta_stupa + "</td></tr>" +
      "<tr><th>Adress</th><td>" + feature.properties.adresa + "</td></tr>" +
      "<tr><th>Services</th><td>" + feature.properties.datum + "</td></tr>" 
      "</table>";.....
onEachFeature:功能(功能,图层){
if(feature.properties){
var content=“”+“Šifra trafostanice”+feature.properties.ts_sifra+
“+”名称“+feature.properties.ts_naziv+”
“代码”+feature.properties.sifra_lampe+“”+
“电源”+feature.properties.tip_lampe+“”+
“电杆类型”+feature.properties.vrsta_stupa+“”+
“地址”+feature.properties.adresa+“”+
“服务”+feature.properties.datum+“”
"";.....
使用上面的代码,我得到如下结果:

所以,我的问题是,是否可以基于数据值更改行的类

(例如,如果表行服务的值为'Nema servisa'添加类 成功(否则保留行不变)


因为您是通过JavaScript生成的,所以这是非常可行的

在那一行,只需检查feature.properties.datum==='Nema Servisa'。如果是,请添加
class=“success”
。如果不是,请不要添加

onEachFeature: function (feature, layer) {
   if (feature.properties) {
     var content = "<table class='table table-striped table-bordered table-condensed'>" + "<tr><th>Šifra trafostanice</th><td>" + feature.properties.ts_sifra + 
     "</td></tr>" + "<tr><th>Name</th><td>" + feature.properties.ts_naziv + "</td></tr>" +  
     "<tr><th>Code</th><td>" + feature.properties.sifra_lampe + "</td></tr>" +
     "<tr><th>Power</th><td>" + feature.properties.tip_lampe + "</td></tr>" +
     "<tr><th>Pole type</th><td>" + feature.properties.vrsta_stupa + "</td></tr>" +
     "<tr><th>Adress</th><td>" + feature.properties.adresa + "</td></tr>" +
     "<tr" + (feature.properties.datum === 'Nema servisa' ? ' class="success"' : '') + "><th>Services</th><td>" + feature.properties.datum + "</td></tr>" 
     "</table>";.....
onEachFeature:功能(功能,图层){
if(feature.properties){
var content=“”+“Šifra trafostanice”+feature.properties.ts_sifra+
“+”名称“+feature.properties.ts_naziv+”
“代码”+feature.properties.sifra_lampe+“”+
“电源”+feature.properties.tip_lampe+“”+
“电杆类型”+feature.properties.vrsta_stupa+“”+
“地址”+feature.properties.adresa+“”+
“服务”+feature.properties.datum+“”
"";.....

因为您是通过JavaScript生成的,所以这是非常可行的

在那一行,只需检查feature.properties.datum==='Nema Servisa'。如果是,请添加
class=“success”
。如果不是,请不要添加

onEachFeature: function (feature, layer) {
   if (feature.properties) {
     var content = "<table class='table table-striped table-bordered table-condensed'>" + "<tr><th>Šifra trafostanice</th><td>" + feature.properties.ts_sifra + 
     "</td></tr>" + "<tr><th>Name</th><td>" + feature.properties.ts_naziv + "</td></tr>" +  
     "<tr><th>Code</th><td>" + feature.properties.sifra_lampe + "</td></tr>" +
     "<tr><th>Power</th><td>" + feature.properties.tip_lampe + "</td></tr>" +
     "<tr><th>Pole type</th><td>" + feature.properties.vrsta_stupa + "</td></tr>" +
     "<tr><th>Adress</th><td>" + feature.properties.adresa + "</td></tr>" +
     "<tr" + (feature.properties.datum === 'Nema servisa' ? ' class="success"' : '') + "><th>Services</th><td>" + feature.properties.datum + "</td></tr>" 
     "</table>";.....
onEachFeature:功能(功能,图层){
if(feature.properties){
var content=“”+“Šifra trafostanice”+feature.properties.ts_sifra+
“+”名称“+feature.properties.ts_naziv+”
“代码”+feature.properties.sifra_lampe+“”+
“电源”+feature.properties.tip_lampe+“”+
“电杆类型”+feature.properties.vrsta_stupa+“”+
“地址”+feature.properties.adresa+“”+
“服务”+feature.properties.datum+“”
"";.....

创建表格时,向每个td元素添加一个
class=“feature property”
。 然后您可以定义此函数,并在生成表后调用它:

function highlightTableRow(match){
    $('.feature-property').each(function(){
        var value = $(this).html();
        if(value === match){
            $(this).addClass('success');  
        }
    });   
}

match
将是您要检查的数据值。在这种情况下,
Nema Servisa

在创建表格时,向每个td元素添加一个
class=“feature property”
。 然后您可以定义此函数,并在生成表后调用它:

function highlightTableRow(match){
    $('.feature-property').each(function(){
        var value = $(this).html();
        if(value === match){
            $(this).addClass('success');  
        }
    });   
}

match
将是您要检查的数据值。在这种情况下,
Nema Servisa

是的,这是一个有效、简洁的答案,谢谢!我甚至对添加这行代码feature.properties.datum=='Nema Servisa'?'class=“danger':''| feature properties.datum!='Nema Servisa'?'class=“success”“:”是的,这是一个有效的、简洁的答案,谢谢!我甚至对添加这行代码feature.properties.datum=='Nema servisa'?'class='danger':''feature.properties.datum!='Nema servisa'?'class='success':'thx表示答案!:)thx表示答案!:)