Skip to content

Instantly share code, notes, and snippets.

@yoga1290
Last active August 29, 2015 13:57
Show Gist options
  • Save yoga1290/9872173 to your computer and use it in GitHub Desktop.
Save yoga1290/9872173 to your computer and use it in GitHub Desktop.
Ember.JS: DS.Store + DS.FixtureAdapter
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>
<script src="http://builds.emberjs.com/canary/ember-data.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars" data-template-name="index">
{{#each}}
{{#link-to 'post' id}}
post#{{id}}
{{/link-to}}
<br>
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name="post">
{{post}}
</script>
</body>
</html>
App = Ember.Application.create({
LOG_TRANSITIONS: true});
App.Router.map(function() {
this.route('post', { path: ':postId' });
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('post');
}
});
App.PostRoute= Ember.Route.extend({
model:function(params){
return this.store.find('post',params.postId);
}
});
App.ApplicationAdapter = DS.FixtureAdapter;
App.Post=DS.Model.extend({
postId: DS.attr('number'),
post: DS.attr('string')
});
App.Post.FIXTURES=[
{
id:1,
post:'Hello Post'
},
{
id:2,
post:'2nd post'
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment