Created
March 5, 2014 05:13
-
-
Save bguiz/9361630 to your computer and use it in GitHub Desktop.
Simple Ember App that displays items using the Master-Detail Pattern, with nested routes, and index routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[simple ember app that display foos using master-detail pattern & nested route & index]" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script> | |
<script src="http://builds.emberjs.com.s3.amazonaws.com/tags/v1.3.2/ember.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script type='text/x-handlebars' data-template-name='application'> | |
<div>{{outlet}}</div> | |
</script> | |
<script type='text/x-handlebars' data-template-name='foos'> | |
<div> | |
{{#each foo in model}} | |
{{#link-to 'foo' foo}} | |
<p>{{foo.id}}</p> | |
{{/link-to}} | |
{{else}} | |
<p>There appears to be no Foos</p> | |
{{/each}} | |
</div> | |
<div> | |
{{outlet}} | |
</div> | |
</script> | |
<script type='text/x-handlebars' data-template-name='foos/index'> | |
select a foo by ID | |
</script> | |
<script type='text/x-handlebars' data-template-name='foo'> | |
<h3>Foo</h3> | |
<p>{{model.id}}</p> | |
<p>{{model.type}}</p> | |
<p>{{model.name}}</p> | |
<p> | |
{{#link-to 'foo.bar' model}}foobar{{/link-to}} | |
{{#link-to 'foo.baz' model}}foobaz{{/link-to}} | |
</p> | |
<div> | |
{{outlet}} | |
</div> | |
</script> | |
<script type='text/x-handlebars' data-template-name='foo/index'> | |
select bar or baz | |
</script> | |
<script type='text/x-handlebars' data-template-name='foo/bar'> | |
<h4>FooBaR</h4> | |
<p>foobarred: {{model.name}} {{model.type}}</p> | |
</script> | |
<script type='text/x-handlebars' data-template-name='foo/baz'> | |
<h4>FooBaZ</h4> | |
<p>foobazzed: {{model.name}} {{model.type}}</p> | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = Ember.Application.create({ | |
LOG_TRANSITIONS: true, | |
LOG_ACTIVE_GENERATION: true, //controllers generated by ember | |
LOG_VIEW_LOOKUPS: true | |
}); | |
App.Router.map(function() { | |
this.resource('foos', function() { | |
this.resource('foo', { path: '/:foo_id'}, function() { | |
this.route('bar'); | |
this.route('baz'); | |
}); | |
}); | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
redirect: function() { | |
this.transitionTo('foos'); | |
} | |
}); | |
App.FoosController = Ember.Controller.extend({ | |
}); | |
App.FoosRoute = Ember.Route.extend({ | |
setupController: function(controller, model) { | |
controller.set('model', [ | |
{id: 1, type: 'a', name: 'foo1'}, | |
{id: 2, type: 'a', name: 'bar1'}, | |
{id: 3, type: 'b', name: 'baz1'}, | |
{id: 4, type: 'b', name: 'goo'}, | |
{id: 5, type: 'a', name: 'gar'}, | |
{id: 6, type: 'b', name: 'gaz'}, | |
{id: 7, type: 'a', name: 'moo'}, | |
{id: 8, type: 'b', name: 'maz'} | |
]); | |
//console.log(controller.get('model')); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment