2011-07-26 6 views
1

私のウェブサイト用のTwitterフィードを作成しようとしていますが、最新のつぶやきを別の部門に表示したいと思います。Twitterフィードwith JQuery - 最近のつぶやきを別の部門に投稿する

ここにこのコードがあります...それぞれのツイートが保存される個々のクラスにターゲットを3つ設定しました。

私の主な問題は、各ツイート(i)のデータをループに格納する方法です。しかし、これは動作していません...誰かがこれでどこが間違っている私に教えてもらえますか?歓声

$(document).ready(function() { 
    // Call the Twitter API to retrieve the last 3 tweets in JSON format for the pcpro Twitter account 
    $.getJSON("http://twitter.com/statuses/user_timeline.json?screen_name=allaboutjames&count=3&callback=?", function(tweetdata) {  

     var t1 = $("#work-thumbs .tweet-1"); 
     var t2 = $("#work-thumbs .tweet-2"); 
     var t3 = $("#work-thumbs .tweet-3"); 

     // For each item returned in tweetdata 
     $.each(tweetdata, function(i,tweet) { 
      // Append the info in li tags to the ul, converting any links to HTML <a href=.. code and convert the tweeted date 
      // to a more readable Twitter format 
      t(i).append("<li>&ldquo;" + urlToLink(tweet.text) + "&rdquo;&ndash; " + relTime(tweet.created_at) + "</li>"); 
     }); 
    }); 
}); 

答えて

1

t(i)は機能しません。代わりにこれを試してみてください:

$(document).ready(function() { 
    // Call the Twitter API to retrieve the last 3 tweets in JSON format for the pcpro Twitter account 
    $.getJSON("http://twitter.com/statuses/user_timeline.json?screen_name=allaboutjames&count=3&callback=?", function(tweetdata) {  
     // For each item returned in tweetdata 
     $.each(tweetdata, function(i,tweet) { 
      // Append the info in li tags to the ul, converting any links to HTML <a href=.. code and convert the tweeted date 
      // to a more readable Twitter format 
      $("#work-thumbs .tweet-"+(1+i)).append("<li>&ldquo;" + urlToLink(tweet.text) + "&rdquo;&ndash; " + relTime(tweet.created_at) + "</li>"); 
     }); 
    }); 
}); 

はまた、jQueryの$.each()はindexInArray(0から始まる)でiを移入することを気づきます。

+1

ここはフィドルhttp://jsfiddle.net/kbKW9/ – Rafay

+0

フィドルを追加してくれてありがとう。それは良いアイデアです。しかし、私のコードは含まれていませんが、わずかに異なる選択肢です。 – middus

関連する問題