如何在未填写 Leaflet 时在弹出窗口中隐藏文本 属性?

How to hide a text property in popup when it's not filled in Leaflet?

我有 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);
            }

并非我所有的对象都有描述。如果我单击没有描述的点,在弹出窗口中 window 我可以看到:

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);
      }