<html>
<head>
<meta charset="utf-8">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
<script src="//builds.emberjs.com/tags/v1.7.0/ember.js"></script>
<script src="//builds.emberjs.com/tags/v1.0.0-beta.9/ember-data.js"></script>
<title>JS Bin</title>
</head>
<body>
<script type="text/x-handlebars" data-template-name="index">
<h3>Posts</h3>
<label>
{{input type="checkbox" checked=displayAuthor}} Display author
</label>
{{#if displayAuthor}}
<div class="list-group">
{{#each posts}}
<div class="list-group-item">
<span class="pull-right">
<span class="text-muted">by</span> {{author.name}}
</span>
{{title}}
</div>
{{/each}}
</div>
{{else}}
<div class="list-group">
{{#each posts}}
<div class="list-group-item">
{{title}}
</div>
{{/each}}
</div>
{{/if}}
</script>
<script type="text/x-handlebars">
<div class="container">
<p>
Keep Ember Inspector "Render Perfomance" tab open and watch render times
when checking and unchecking "Display author".
</p>
{{outlet}}
<p>
<span class="label label-info">Note</span> Ember Inspector only works when
code is run in separate tab/window.
</p>
</div>
</script>
</body>
</html>
var App = Em.Application.create();
App.User = DS.Model.extend({
name: DS.attr('string')
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.belongsTo('user')
});
App.IndexController = Em.Controller.extend({
displayAuthor: false,
posts: function() {
return this.get('store').all('post');
}.property(),
displayDidChange: function() {
// Here data is always pushed into store to simulate server response to a search,
// page change, etc.
// This forces Ember Data to rewire models (discarding computed properties
// cached results).
this.get('store').pushPayload('post', {
posts: [
{ id: "1", title: "Lorem ipsum dolor sit amet", author: "1" },
{ id: "2", title: "Consectetur adipiscing elit", author: "1" },
{ id: "3", title: "Nullam quis eros efficitur enim ultrices", author: "1" },
{ id: "4", title: "Vel convallis sodales", author: "2" },
{ id: "5", title: "Erat risus consectetur massa", author: "1" },
{ id: "6", title: "In euismod velit turpis nec magna", author: "1" },
{ id: "7", title: "Nullam sollicitudin consequat eros a congue", author: "2" },
{ id: "8", title: "Duis sit amet nulla vel sapien venenatis iaculis", author: "1" },
{ id: "9", title: "Vel semper nibh. Morbi scelerisque ipsum", author: "1" },
{ id: "10", title: "Vivamus eleifend arcu ut nisl fringilla egestas", author: "2" }
],
users: [
{ id: "1", name: "root" },
{ id: "2", name: "someone" }
]
});
}.observes('displayAuthor').on('init')
});
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard 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. |