【问题标题】:Get facebook pics to Titanium将 Facebook 照片获取到 Titanium
【发布时间】:2012-05-21 11:58:23
【问题描述】:

我有一个乐队,我想在我们的 Titan 应用程序中创建一个部分,显示我们的 Facebook 粉丝专页图片。

我已经到了可以在表格行中获取图片的部分,但是当我单击它们时,它只显示最后一张。

有点奇怪……

这是我的代码,所以也许你可以帮忙看看我做错了什么......

var win = Ti.UI.currentWindow;

win.hideNavBar();


Ti.UI.backgroundColor = '#dddddd';




var url = "https://graph.facebook.com/98604492365/photos";
var win = Ti.UI.createWindow();
var table = Ti.UI.createTableView();
var tableData = [];
var json, data, position,picture, source,link,icon;

var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);

json = JSON.parse(this.responseText);
for (i = 0; i < json.data.length; i++) {
    data = json.data[i];
    row = Ti.UI.createTableViewRow({
        height:'60dp'
    });
  var  name = Ti.UI.createLabel({
        text:data.position,
        font:{
            fontSize:'18dp',
        fontWeight:'bold'
    },
    height:'auto',
    left:'50dp',
    top:'5dp',
    color:'#000',
    touchEnabled:true
    });



  // Avatar
            var img = Ti.UI.createImageView({
                image   : data.picture,
                width   : 35,
                height  : 35,
                top     : 5,
                bottom  : 5,
                borderRadius: 5,
                left    : 5
            });
            row.add(img);


    row.add(name);

    tableData.push(row);
    }

table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT:   " + this.responseText);
Ti.API.debug("ERROR:  " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});

xhr.open("GET", url);
xhr.send();

// Handle a click event on the table
    table.addEventListener('click',function(e) {
        // Create the new window with the link from the post
        var faceWindow = Ti.UI.createWindow({
            title   : data.name,
            modal   : true,
            barColor: '#050505',
            backgroundColor: '#050505'              
        });
        var webView = Ti.UI.createWebView({url: data.source});
        faceWindow.add(webView);

        // Create the close button to go in the left area of the navbar popup
        var close = Titanium.UI.createButton({
            title: 'Close',
            style: Titanium.UI.iPhone.SystemButtonStyle.PLAIN
        });
        faceWindow.setLeftNavButton(close);

        // Handle the close event
        close.addEventListener('click',function() {
            faceWindow.close();
        });



        faceWindow.open();
    });


win.add(table);
win.open();

请帮助我,我正在失去理智......

感谢

//R

【问题讨论】:

    标签: facebook json gallery titanium appcelerator-mobile


    【解决方案1】:

    查看您的代码,我发现缩进是错误的。看到这一点,我注意到您在事件处理程序“单击”中使用了 data.name 和 data.source。此数据似乎是在 foreach 循环中设置的。

    点击事件不是这样工作的。它是事件驱动的。您最好将源网址和名称设置为行上的变量。

    row.photoName = data.name;
    row.photoSource = data.source;
    

    然后,在事件处理程序中,您将e 设置为回调变量。使用它:

    e.row.photoName;
    e.row.photoSource;
    

    【讨论】:

    • 你是个天才,我向你鞠躬!像魅力一样工作!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多