Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.38 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Knockoutjs super basics
  2. TwitterGet = function() {
  3.   var recent_tweets = ko.observableArray();
  4.   var twitter_image = ko.observable();
  5.  
  6.   var component = this;  
  7.   var url = 'https://twitter.com/search.json?callback=?';
  8.  
  9.   this.attributes.twitter_user_handle.subscribe(function(value) {
  10.  
  11.     var url = 'https://twitter.com/search.json?callback=?';
  12.     var twitter_parameters = {
  13.       include_entities: true,
  14.       include_rts: true,
  15.       q: 'from:' + value,  
  16.       count: '3'
  17.     }
  18.  
  19.   $.getJSON(url,twitter_parameters,
  20.   function(json) {
  21.     twitter_image(json.results[0].profile_image_url);
  22.       result = json.results;
  23.       recent_tweets.push(result);
  24.   });
  25.  });
  26. };
  27.        
  28. <div class="tweet" id="first-tweet">
  29. <span class="handle"><a href="#" target="_blank" data-bind-component_<%=component.id-%>="inline_edit: attributes.twitter_user_handle"></a>
  30. </span><span data-bind-component_<%=component.id-%>="inline_edit: recent_tweets.slice(-1)[0][1].text"></span><br>
  31. <a href="#">share</a>
  32. <a href="#" target="_blank">retweet</a>
  33. <a href="#">reply</a></div>
  34.  
  35. <div class="tweet" id="second-tweet">
  36. <span class="handle"><a href="#" target="_blank" data-bind-component_<%=component.id-%>="inline_edit: attributes.twitter_user_handle"></a>
  37. </span><span data-bind-component_<%=component.id-%>="inline_edit: recent_tweets.slice(-1)[0][2].text"></span><br>
  38.        
  39. recent_tweets.push(result);
  40.        
  41. recent_tweets(result);