Skip to content

Instantly share code, notes, and snippets.

@patmood
Last active December 28, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmood/7543903 to your computer and use it in GitHub Desktop.
Save patmood/7543903 to your computer and use it in GitHub Desktop.
Ember app that reads hacker news feed with via JSONP api
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="http://code.jquery.com/jquery-2.0.2.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="application">
<h1>ember-latest jsbin</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Index Content:</h2>
<ul>
{{#each item in model}}
<li>{{item.title}}</li>
{{/each}}
</ul>
</script>
</body>
</html>
App = Ember.Application.create({});
App.IndexRoute = Ember.Route.extend({
model: function() {
return App.Item.all();
}
});
App.Item = Ember.Object.extend({});
App.Item.reopenClass({
all: function() {
return $.getJSON("http://api.ihackernews.com/page?format=jsonp&callback=?").then(function(response) {
var items = [];
response.items.forEach( function (item) {
items.push( App.Item.create(item) );
});
return items;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment