1

仅当电话存在时我将如何进行此附加,如果电话不存在则跳过

for (var i in data.businesses) {
    $('body').append( "<p>" + data.businesses[i].telephone + "</p>");
}
4

3 回答 3

1

尝试

$.each(data.businesses, function(index, business){
    if(business.telephone){
        $('body').append( "<p>" + business.telephone + "</p>");
    }
});
于 2013-04-21T15:42:38.083 回答
1
for (var i in data.businesses) {
    if(data.businesses[i].telephone)
        $('body').append( "<p>" + data.businesses[i].telephone + "</p>");
 }
于 2013-04-21T15:45:46.610 回答
0

尝试这个:

for (var i in data.businesses) {
    if(data.businesses[i].telephone  !== null and data.businesses[i].telephone !== undefined) {
        $('body').append( "<p>" + data.businesses[i].telephone + "</p>");
    }
}
于 2013-04-21T15:42:40.300 回答