Я пытаюсь сгенерировать некоторый HTML-контент для информационного окна карт Google. У меня есть 7 значений, которые должны отображаться, если они не равны null, undefined или "" (пустая строка).
Но, очевидно, мой if (e.Property! = Null || e.Property! = "Undefined" || e.Property == "")
не работает, когда свойство
равно не определено
. Чаще всего дело в том, что e.Email
не определено. Поэтому вместо того, чтобы пропускать эту часть, мой код по-прежнему вставляет часть html + "
. И когда я
alert ()
e.Email, он возвращает undefined
, который он должен ловить и пропускать, если это так.
Я пробовал написать if (typeof e.Property! = Null || typeof e.Property! = "Undefined" || typeof e. Property == "")
, но это не имело значения.
// 'e ' is JSON object
var generateHTML = {
init: function(e) {
if (e != null || e != "undefined"){
generateHTML.check(e);
}
},
check: function (e) {
if(e.Title != null || e.Title != "undefined" || e.Title == ""){
html = html + "<b>"+e.Title+"</b>";
}
if(e.Address != null || e.Address != "undefined" || e.Address == ""){
html = html +"<br />"+ e.Address;
}
if(e.Zipcode != null || e.Zipcode != "undefined" || e.Zipcode == ""){
html = html +"<br />"+ e.Zipcode+", ";
}
if(e.City != null || e.City != "undefined" || e.City == ""){
html = html + e.City;
}
if(e.Phone != null || e.Phone != "undefined" || e.Phone == ""){
html = html +"<br />"+ e.Phone;
}
if(e.Email != null || e.Email != "undefined" || e.Email == ""){
html = html +"<br />"+ e.Email;
}
if(e.WebAddress != null || e.WebAddress != "undefined" || e.WebAddress == ""){
html = html +"<br />"+ e.WebAddress;
}
return html;
}
};