我有 geoJson 层:
var test_layer = {
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [{
"type": "Feature",
"properties": {
"name": "Name 1",
"description": "Desc 1",
"geometry": {
"type": "Point",
"coordinates": [
72.6, 44.3]
}
}]
}
和弹出功能:
onEachFeature: function (feature, layer) {
var popupContent = "<div class=popup><b>Object's name: </b>" + feature.properties.name + "<br /><b>Object's description: </b>" + feature.properties.description</p>";
layer.bindPopup(popupContent);
}
并非我的所有对象都有描述。如果我点击没有描述的点,在弹出窗口中我可以看到:
Description: undefined
当值为空或已删除时,我应该更改什么才能将描述字段隐藏在弹出窗口中?
最佳答案
试试这个:
onEachFeature: function (feature, layer) {
var popupContent = "<div class=popup><b>Object's name: </b>" + feature.properties.name;
if(typeof(feature.properties.description) !== 'undefined'){
popupContent += "<br /><b>Object's description: </b>" + feature.properties.description+"</p>"
}
layer.bindPopup(popupContent);
}
关于javascript - 当传单中未填写文本属性时,如何隐藏弹出窗口中的文本属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29210828/