这是我的异步方法:
function getAlbumCovers() {
//first check to see if profile pics already exist in user model
//create a collection
var usersCollection = Alloy.Collections.user;
facebookModule.requestWithGraphPath('me/albums', {
fields : 'id,name,cover_photo,count,created_time'
}, 'GET', function(graphResp) {
//show view indicator before data is fetched
$.view_indicator.visible = true;
if (graphResp.success) {
if (graphResp.result) {
var rows = [];
var data = JSON.parse(graphResp.result).data;
var i=0;
for (x in data) {
Ti.API.debug(JSON.stringify(data[x]));
var Albums = String.format("%s (%d)", data[x].name, data[x].count);
console.log(Albums);
var row = Titanium.UI.createTableViewRow({
width : '100%',
height : 'auto'
});
var image = Titanium.UI.createImageView({
image : "https://graph.facebook.com/" + (data[x].cover_photo || 0) + "/picture?access_token=" + Ti.Facebook.accessToken,
top : 0,
left : 0,
width : 100,
height : 100
});
var title = Titanium.UI.createLabel({
text : test,
top : 0,
left : 110,
width : 'auto',
height : 'auto'
});
row.add(image);
row.add(title);
rows.push(row);
}
console.log(rows);
//set table rows
$.tableview.setData(rows);
//end
$.view_indicator.visible = false;
}
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});
}
问题,这是console.log(rows);
的输出(如果我继续关闭并重新打开窗口):
[INFO] : Profile Pictures (4)
[INFO] : Cover Photos (1)
[INFO] : Mobile Uploads (0)
[INFO] : Timeline Photos (0)
[INFO] : Untitled Album (0)
[INFO] : Untitled Album (1)
// Fine
[INFO] : Profile Pictures (4)
[INFO] : Cover Photos (1)
[INFO] : Mobile Uploads (0)
[INFO] : Timeline Photos (0)
[INFO] : Untitled Album (0)
[INFO] : Untitled Album (1)
// Fine again
[INFO] : Profile Pictures (4)
[INFO] : Cover Photos (1)
[INFO] : Mobile Uploads (0)
[INFO] : Timeline Photos (0)
[INFO] : Untitled Album (90668843350925705704470860216788845156409915121482525099460797528722583431186535307341891426094773480786356228821741890211882156053220804540899892654174105362205327540955324744929635810063978450130488142173895865528091904584042889722878136145298291869241384290654277861376)
[INFO] : Untitled Album (1)
// Bug
[INFO] : Untitled Album (1)
[INFO] : Profile Pictures (4)
[INFO] : Cover Photos (1)
[INFO] : Mobile Uploads (0)
[INFO] : Timeline Photos (0)
[INFO] : Untitled Album (0)
// Fine
有时这行代码会随机失败,导致:
var Albums = String.format("%s (%d)", data[x].name, data[x].count);
我不知道为什么会发生这种情况,或者为什么表格中的数据表现不正常。任何想法,干杯。
答案 0 :(得分:0)
String.format("%s (%d)", data[x].name, data[x].count);
这就是造成这个错误的原因。您可以通过将两个不同的字符串连接在一起来纠正它,一个用于计数,另一个用于名称