Skip to content

Instantly share code, notes, and snippets.

@yoga1290
Last active August 29, 2015 13:57
Show Gist options
  • Save yoga1290/9808441 to your computer and use it in GitHub Desktop.
Save yoga1290/9808441 to your computer and use it in GitHub Desktop.
Ember.JS Route Model + Promises
body {
font-family: Helvetica, Arial, sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars" data-template-name="index">
{{#linkTo "pull" 0}}
1st pull
{{/linkTo}}
<br>
{{#linkTo "pull" 1}}
2nd pull
{{/linkTo}}
{{!outlet}}
</script>
<script type="text/x-handlebars" data-template-name="pull">
data={{url}}
{{#link-to 'pull.url' this}} Edit {{/link-to}}
<br>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="pull/url">
{{textarea value=url }}
</script>
</body>
</html>
App = Ember.Application.create({
LOG_TRANSITIONS: true});
App.Router.map(function() {
this.resource('pull', { path: ':postId' },function(){
this.route('url');
});
});
App.PullRoute = Ember.Route.extend({
model: function(params) {
return Ember.$.getJSON('https://api.github.com/repos/emberjs/ember.js/pulls').then(function(data) {
return data[params.postId];
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment