Displaying the tweets
We have a URL address that responds with a JSON-formatted list of tweets. There are corresponding controllers and route classes, which are defined by default from Ember.js. However, we need to set a model and get the handle from the browser's address, so we will create our own classes. This can be seen as follows:
App.SocialFeedTweetsRoute = Ember.Route.extend({ model: function(params) { this.set('handle', params.handle); return Ember.$.getJSON('/tweets/' + params.handle); }, setupController: function(controller, model) { controller.set("model", model); controller.set("handle", this.get('handle')); } }); App.SocialFeedTweetsController = Ember.ArrayController.extend({ handle: '', formattedHandle: function() { return "<a href='http://twitter.com/" + this.handle + "'>@" + this.handle + '</a>'; }.property('handle') });
The dynamic segment from the URL comes to the Route's model
function in the params
argument. We will...