根据单元格的值更改表的行类 [英] Change row class of table based on value of cell

查看:115
本文介绍了根据单元格的值更改表的行类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据数据单元格的值更改行类(使用引导程序)? 像这样的东西: (这里我将类硬编码为行)

Is it possible to change row class (using bootstrap) based of value of data cell? Something like this: (here I hard coded class into row)

这是代码片段

 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>";.....

使用上面的代码,我得到的是这样的:

Using code above i get something like this:

所以,我的问题是可以根据数据值更改行的类吗?

So, my question is is it possible to change class of row based of data value?

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

(Example if value of table row Services is 'Nema servisa' add class success else leave row unchanged)

推荐答案

由于您是通过JavaScript生成的,因此这是非常可行的.

Since you are generating this via JavaScript yes this is very doable.

在该行上,仅检查是否为feature.properties.datum === 'Nema Servisa'.如果是,请添加class="success".如果没有,那就不要.

On that row just check to see if feature.properties.datum === 'Nema Servisa'. If yes, add class="success". If not, don't.

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>";.....

这篇关于根据单元格的值更改表的行类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆