是否可以根据数据单元格的值更改行类(使用引导程序)?
像这样的东西:
(这里我将类硬编码成行)
这是代码片段
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>";.....
所以,我的问题是是否可以根据数据值更改行类?
(例如,如果表行服务的值是'Nema servisa'添加类 成功否则保持行不变)
答案 0 :(得分:1)
因为你是通过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>";.....
答案 1 :(得分:1)
创建表格时,为每个td元素添加class="feature-property"
。
然后你可以定义这个函数并在生成表后调用它:
function highlightTableRow(match){
$('.feature-property').each(function(){
var value = $(this).html();
if(value === match){
$(this).addClass('success');
}
});
}
match
将是您要检查的数据值..在这种情况下,Nema Servisa