facebook模块,获取数据时出错

facebook module, buggy when fetching data?

本文关键字:出错 数据 获取 模块 facebook      更新时间:2023-09-26

这是我的异步方法:

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);

我不知道为什么会发生这种情况,也不知道为什么表上的数据表现不稳定。任何想法,干杯。

String.format("%s (%d)", data[x].name, data[x].count);

这就是导致错误的原因。您可以通过将两个不同的字符串连接在一起进行更正,一个用于计数,另一个用于名称