0

Twitter API を使用してツイートを取得し、それを変数に割り当てています。そのようです。

        self.tweets = $.map(data.results, function(tweet){
                return{
                    author: tweet.from_user,
                    url: 'http://twitter.com/' + tweet.from_user + '/status/' + tweet.id_str,
                    image: tweet.profile_image_url,
                    tweet: tweet.text
                };
            });

私は私のために働いています。ツイートを HTML に追加しています。テキストはそのようです..

 @drwarwick Hi David! Looking forward to catching up with you, but may not get in there today due to work commitments...

私が今やりたいことは、@drwarwick を @drwarwick にラップして、それに応じてスタイルを設定してリンクできるようにすることです。ツイートでそのような単語を jquery で検索するにはどうすればよいですか。ありがとう。

編集>>>>>

上記でstackoverflowのようなことが行われています。テキストの色を変更しました。

4

1 に答える 1

1

それを行うためのヘルパーメソッドを書きました。

function HighLight(input)
{
    var output="";
    var items=input.split(" ");
    $.each(items,function(index,item){
       var word=items[index];
       if(word.match("^@"))
       {
           word="<span class='highlightSpan'>"+word+"</span>";  
       }                         
       output+=word+" ";
    });    
    return output;
}

作業例: http: //jsfiddle.net/ZSafX/27/

コードを変更して、このように含めることができます

    self.tweets = $.map(data.results, function(tweet){
            return{
                author: tweet.from_user,
                url: 'http://twitter.com/' + tweet.from_user + '/status/' + tweet.id_str,
                image: tweet.profile_image_url,
                tweet: HighLight(tweet.text)
            };
        });
于 2012-04-30T03:53:52.117 に答える