July 2017
Intermediate to advanced
374 pages
8h
English
Let's develop a JavaScript that will make a REST call to the backend service and add the tweet content provided from the HTML page.
Let's create a file with the name tweet.js inside the static directory that we created earlier with the following code:
function Tweet(data) { this.id = ko.observable(data.id); this.username = ko.observable(data.tweetedby); this.body = ko.observable(data.body); this.timestamp = ko.observable(data.timestamp); } function TweetListViewModel() { var self = this; self.tweets_list = ko.observableArray([]); self.username= ko.observable(); self.body= ko.observable(); self.addTweet = function() { self.save(); self.username(""); self.body(""); }; $.getJSON('/api/v2/tweets', ...Read now
Unlock full access