Мне нужно удалить ключ и значение из всплывающего окна, если они не существуют. Я был в состоянии сделать это нормально с условными утверждениями. Однако во всплывающей переменной у меня есть HTML теговый текст, который может быть префиксом для значений, которые могут быть пустыми. Как я могу удалить их, когда условие выполнено? Вот что я пытался Результаты отображаются во всплывающем окне " phone :". Вот мой код.
name: "Mariza",
properties: {
description: "Italian-inspired fare dished out in an airy loft building with an industrial-chic vibe.",
coordinates: [29.9629337, -90.0501008],
url: 'http://marizaneworleans.com/',
phone: '(504) 598-5700',
icon: 'svgs/restaurant-15.svg'
}
}];
// declare variable for accessing object properties
var props = hotspots[i].properties;
var icon = L.icon({
iconUrl: props.icon,
iconSize: [40, 40],
popupAnchor: [0, -22],
className: "icon"
});
if (hotspots[i].properties.description) {
console.log ("I have a description, include in popup")
} else if (hotspots[i].properties.description = '')
console.log("I have no description, exclude from popup");
if (hotspots[i].properties.url) {
console.log ("I have a url, include in popup")
} else if (hotspots[i].properties.url = '')
console.log("I have no url, exclude from popup");
if (hotspots[i].properties.phone) {
console.log ("I have a phone, include in popup")
var popup = `<h3>${hotspots[i].name}</h3>
<p>${props.description}</p>
<p><b>website</b>: <a href='${props.url}'>${props.url}</a></p>
<p><b>phone</b>: ${props.phone}</p>`
var marker = L.marker(hotspots[i].properties.coordinates, {
icon: icon
})
.addTo(map)
.bindPopup(popup);
} else if (hotspots[i].properties.phone = '')
console.log("I have no phone, exclude from popup")
var popupPhone = `<h3>${hotspots[i].name}</h3>
<p>${props.description}</p>
<p><b>website</b>: <a href='${props.url}'>${props.url}</a></p>`
var marker = L.marker(hotspots[i].properties.coordinates, {
icon: icon
})
.addTo(map)
.bindPopup(popupPhone);
// assign a string, wrapping the name of the place within two HTML bold tags
var popupPhone = `<h3>${hotspots[i].name}</h3>
<p>${props.description}</p>
<p><b>website</b>: <a href='${props.url}'>${props.url}</a></p>`
var popup = `<h3>${hotspots[i].name}</h3>
<p>${props.description}</p>
<p><b>website</b>: <a href='${props.url}'>${props.url}</a></p>
<p><b>phone</b>: ${props.phone}</p>`
var marker = L.marker(hotspots[i].properties.coordinates, {
icon: icon
})
.addTo(map)
.bindPopup(popup);