Going back to movienow.nearbytweets.js
, we can update the event listener to take the JSON object returned from the Web Worker. If you look at the following code that we will add to the event listener body, you will see that we get the returned data and loop through the result set to capture the text of each tweet:
var data = objectifyJSON(e.data); var nearbyTweets = ''; for (var i=0; i<data.results.length; i++) { nearbyTweets += '<li>'+data.results[i].text+'</li>'; } var tweetCounter = (data.results.length==1) ? data.results.length+" tweet" : data.results.length+" tweets"; $(theater) .append(' <span class="tweet-count">('+ tweetCounter +')</span>') .parents('li').append('<section class="nearby-tweets"><h3>Nearby Tweets</h3><ul>'+nearbyTweets+'</ul></section>') .find('.tweet-count').click(that.showNearbyTweets) .parents('li').find('.nearby-tweets').click(that.hideNearbyTweets);