<html>
<head>
<meta name="description" content="Minimalist Ember JSBin" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<script src="//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/ember-data-latest.js"></script>
<title>Ember JS Example</title>
</head>
<body>
<script type="text/x-handlebars">
<div class="container">
<h1>Ember JS Example</h1>
<ul>
<li>{{#linkTo 'welcome'}}View Welcome Page{{/linkTo}}</li>
<li>{{#linkTo 'other'}}View Other Page{{/linkTo}}</li>
<li>{{#linkTo 'students.index'}}Students{{/linkTo}}</li>
</ul>
<div class="alert alert-info">
<h4>Global Navigation Pulldown</h4>
{{view App.NavSelectView
viewName="select_requirement"
contentBinding="studModel"
optionLabelPath="content.name"
optionValuePath="content.id"
prompt="Pick a student:"
}}
</div>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="welcome">
<h2>Welcome Page</h2>
<a href="#" class="btn btn-primary" {{action doit}}>Do Something</a>
{{ outlet }}
</script>
<script type="text/x-handlebars" data-template-name="other">
<h2>Other Page</h2>
{{ outlet }}
</script>
<script type="text/x-handlebars" data-template-name="students">
{{ outlet }}
</script>
<script type="text/x-handlebars" data-template-name="students/index">
<div class="alert alert-success">
<h4>Local Navigation Pulldown</h4>
{{view App.NavSelectView
viewName="select_requirement"
contentBinding="controller"
optionLabelPath="content.name"
optionValuePath="content.id"
prompt="Pick a student:"
}}
</div>
<h2> All Students </h2>
<table class="table table-striped table-hover">
<thead>
<tr>
<th><h4>Name:</h4></th>
<th><h4>Grade:</h4></th>
<th><h4>GPA:</h4></th>
</tr>
</thead>
<tbody>
{{#each}}
<tr>
<td><h4>{{#linkTo "student.index" this}} {{name}} {{/linkTo}}</h4></td>
<td>{{grade}}</td>
<td>{{gpa}}</td>
</tr>
{{/each}}
</tbody>
</table>
</script>
<script type="text/x-handlebars" data-template-name="student">
<h2>Student</h2>
<h3>{{name}}</h3>
<h4>{{grade}}</h4>
<h4>{{gpa}}</h4>
</script>
</body>
</html>
App = Ember.Application.create();
// Router
App.Router.map(function() {
this.resource('welcome', { path: '/' }); // Welcome route
this.resource('other', { path: 'other' }); // Other route
this.resource("students", function(){
this.resource("student", { path: ":student_id" }, function(){});
});
});
App.ApplicationRoute = Ember.Route.extend({
events: {
doit: function() {
App.doSomething();
}
}
});
App.ApplicationController = Ember.ObjectController.extend({
studModel: function(){
return App.Student.find();
}.property(),
selectStudent: function(studentId){
this.transitionToRoute('student', studentId);
}
});
App.StudentsIndexRoute = Em.Route.extend({
model: function() {
return App.Student.find();
},
events: {
selectStudent: function(studentId){
this.transitionTo('student', studentId);
}
}
});
App.StudentRoute = Em.Route.extend({
model: function(params) {
return App.Student.find(params.student_id);
}
});
App.StudentsIndexController = Ember.ArrayController.extend({
});
// Custom Views
App.NavSelectView = Ember.Select.extend({
valueDidChange: Ember.observer(function() {
this._super();
// alert("select value: " + this.get('value'));
this.get('controller').send('selectStudent', this.get('value'));
}, 'value')
});
// Generic function to try stuff
App.doSomething = function(){
alert("try it...");
};
// Models
App.Store = DS.Store.extend({
adapter: 'DS.FixtureAdapter'
});
App.Student = DS.Model.extend({
name: DS.attr('string'),
grade: DS.attr('string'),
gpa: DS.attr('number')
});
// Fixture Data
App.Student.FIXTURES = [{
id: 1,
name: "John",
grade: "9",
gpa: 3.2
},
{
id: 2,
name: "Mary",
grade: "12",
gpa: 3.9
},
{
id: 3,
name: "Jane",
grade: "10",
gpa: 3.6
},
{
id: 4,
name: "Frank",
grade: "11",
gpa: 2.9
},
{
id: 5,
name: "Bill",
grade: "10",
gpa: 2.1
},
{
id: 6,
name: "James",
grade: "12",
gpa: 3.9
}
];
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. |