我是钛的新手,我正在学习钛的 JSon Parsing。我正在访问特定屏幕名称的推文以及他/她的个人资料图片。它对推文的关注效果很好,但没有显示该推文的个人资料图片。
我的 Tweet.js 文件是:
// Create variable "win" to refer to current window
var win = Titanium.UI.currentWindow;
// Function loadTweets()
function loadTweets()
{
// Empty array "rowData" for our tableview
var rowData = [];
var avatar;
// Create our HTTP Client and name it "loader"
var loader = Titanium.Network.createHTTPClient();
// Sets the HTTP request method, and the URL to get data from
loader.open("GET","http://api.twitter.com/1/statuses/user_timeline.json?screen_name=SenchaTouch");
// Runs the function when the data is ready for us to process
loader.onload = function()
{
var tweets = eval('('+this.responseText+')');
alert(tweets);
for (var i = 0; i < tweets.length; i++)
{
var tweet = tweets[i].text; // The tweet message
var user = tweets[i].user.screen_name; // The screen name of the user
avatar = tweets[i].user.profile_image_url; // The profile image
// Create a row and set its height to auto
var row = Titanium.UI.createTableViewRow({height:'auto'});
// Create the view that will contain the text and avatar
var post_view = Titanium.UI.createView({
height:'auto',
layout:'vertical',
top:5,
right:5,
bottom:5,
left:5
});
// Create image view to hold profile pic
var av_image = Titanium.UI.createImageView({
url:'KS_nav_ui.png', // the image for the image view
top:0,
left:0,
height:48,
width:48
});
post_view.add(av_image);
// Create the label to hold the screen name
var user_lbl = Titanium.UI.createLabel({
text:user,
left:54,
width:120,
top:-48,
bottom:2,
height:16,
textAlign:'left',
color:'#444444',
font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
});
post_view.add(user_lbl);
// Create the label to hold the tweet message
var tweet_lbl = Titanium.UI.createLabel({
text:tweet,
left:54,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
post_view.add(tweet_lbl);
// Add the post view to the row
row.add(post_view);
// Give each row a class name
row.className = "item"+i;
// Add row to the rowData array
rowData[i] = row;
}
// Create the table view and set its data source to "rowData" array
var tableView = Titanium.UI.createTableView({data:rowData});
//Add the table view to the window
win.add(tableView);
};
// Send the HTTP request
loader.send();
}
loadTweets();
// 有没有人能找出缺陷??任何帮助,将不胜感激。提前感谢:)