<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars">
{{render "artists"}}
</script>
<script type="text/x-handlebars" data-template-name="artists">
{{#each artist in controller}}
<h3>{{ artist.name }}
<button {{action 'toggleExpanded' on='click'}}>toggle expand</button>
</h3>
{{#if artist.isExpanded}}
{{render 'albums' artist.albums}}
{{/if}}
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name="albums">
{{#each album in controller}}
<h5>{{ album.year }} - {{ album.name }}
<button {{action 'toggleExpanded' on='click'}}>toggle expand</button>
</h5>
{{#if controllers.artist.isAlbumsExpanded}}
{{render 'songs' album.songs}}
{{/if}}
{{/each}}
</script>
<script type="text/x-handlebars" data-template-name='songs'>
{{#each song in controller}}
<h6>{{song.tracknumber}} - {{song.name}}</h6>
{{/each}}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.1.2/ember.min.js"></script>
<!--script src="http://emberjs.com.s3.amazonaws.com/getting-started/ember-data.js"></script-->
<script src="https://rawgithub.com/components/ember-data/master/ember-data.min.js"></script>
</body>
</html>
window.App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter.extend();
App.ApplicationRoute = Ember.Route.extend({
setupController: function(){
this.controllerFor('artists').set('model', this.store.find('artist')) ;
}
});
App.ArtistsController = Ember.ArrayController.extend({
itemController: 'artist'
});
App.ArtistController = Ember.ObjectController.extend({
isExpanded: false,
isAlbumsExpanded: false,
actions: {
toggleExpanded: function() {
this.toggleProperty('isExpanded');
}
}
});
App.AlbumsController = Ember.ArrayController.extend({
itemController: 'album'
});
App.AlbumController = Ember.ObjectController.extend({
needs: ['artist'],
actions: {
toggleExpanded: function() {
this.toggleProperty('controllers.artist.isAlbumsExpanded');
}
}
});
App.Artist = DS.Model.extend({
name: DS.attr('string'),
albums: DS.hasMany('album', {async: true})
});
App.Album = DS.Model.extend({
name: DS.attr('string'),
year: DS.attr('number'),
songs: DS.hasMany('song', {async: true}),
artist: DS.belongsTo('artist')
});
App.Song = DS.Model.extend({
tracknumber: DS.attr('number'),
name: DS.attr('string'),
album: DS.belongsTo('album')
});
App.Artist.FIXTURES = [
{
id: 1,
name: 'The Beatles',
albums: [1]
}
];
App.Album.FIXTURES = [
{
id:1,
year: 1964,
name: 'A Hard Days Night',
songs: [1,2,3,4]
}
];
App.Song.FIXTURES = [
{
tracknumber: 1,
id: 1,
name: "A Hard Day's Night"
},
{
tracknumber: 2,
id: 2,
name: "I Should Have Known Better"
},
{
tracknumber: 2,
id: 3,
name: "If I Fell"
},
{
tracknumber: 2,
id: 4,
name: "I'm Happy Just To Dance Wit"
}
];
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |