0
我从facebook获取专辑名称并使用下面的代码将它们写在页面上。 问题是它还包括未定义的,所以它写了两个“墙照片”,所以我怎样才能防止它写出未定义的?来自facebook api的未定义响应数据?
FB.api('/xxxxxxxxxxxxxxx/albums', function(response) {
if (response && response.data && response.data.length){
var ul = document.getElementById('fb-albumslist');
for (var i=0, l=response.data.length; i<l; i++) {
if (response.data !== "undefined"){
var
album = response.data[i],
li = document.createElement('li'),
a = document.createElement('a');
a.innerHTML = album.name;
a.href = album.link;
li.appendChild(a);
ul.appendChild(li);
}
}
}
});
在页面上它写出:
Wall Photos
Wall Photos (this is undefined)
Cover Photos
Profile Picture
林与尝试“{但是我不知道怎么做‘(未定义如果response.data ==!’)” ? 任何输入赞赏,谢谢!
喜ifaour和感谢,但我不能得到它的工作,如果我用你的代码,我得到这个错误:类型错误:“未定义”不是(评估“album.link”)和Im对象不知道该怎么办?我把它放在“if(response.data!==”undefined“){” – 2012-03-22 08:16:34
只是放在这行之前:'a.innerHTML = album.name;' – ifaour 2012-03-22 09:58:18
非常感谢ifaour,效果很棒! – 2012-03-24 07:00:10