<script type="text/x-handlebars-template" data-template-name="index">
<p>Guess who talks today? {{your-variable-name}}</p>
</script>
<script type="text/x-handlebars-template" data-template-name='application'>
<p>Static content shown in all pages</p>
<p>{{#link-to 'about'}}Link for About{{/link-to}}</p>
{{outlet}}
</script>
<script type="text/x-handlebars-template" data-template-name='about'>
<h1>I will be rendered when the route /about is reached!</h1>
</script>
App.Router.map(function(){
this.route("about");
this.resource("posts", function(){
this.route("new");
});
this.resource("post", { path: "/post/:post_id" });
});
App.PostRoute = Ember.Route.extend({
model: function(params){
return this.store.find('post', params.post_id);
// return [ { id: 1, title: "Bla", author: "Dude" } ];
}
setupController: function(controller, model) {
this.controllerFor('topPost').set('model', model);
}
});
App.Person = Ember.Object.extend({
helloWorld: function(){ alert("Hi, my name is " + this.get('name')); }
});
var leo = App.Person.create({ name: 'Leonardo Vasconcelos' });
leo.helloWorld();
App.User = Ember.Object.extend({
validUsername: Ember.computed.match('username', /^[a-z0-9]+$/),
adult: Ember.computed.gte('age', 18),
canadian: Ember.computed.equal('country', 'CA'),
canVote: Ember.computed.and('adult', 'canadian')
});
App.Person = Ember.Object.extend({
fullname: function(){
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
App.Person = Ember.Object.extend({
fullname: Ember.computed('firstName', 'lastname', function(){
return this.get('firstName') + ' ' + this.get('lastName');
})
});
myObserver: function(){
alert('Wow! What a view!');
}.observes('bird', 'cloud')
myObserver: Ember.observer('bird', 'cloud', function(){
alert('Wow! What a view!');
})
person.addObserver('bird', function(){});
wife = Ember.Object.create({
householdIncome: 80000
});
husband = Ember.Object.create({
wife: wife,
householdIncome: Ember.computed.alias('wife.householdIncome')
});
App.Book = DS.Model.extend({
title: DS.attr(),
launchedAt: DS.attr('date'),
rating: DS.attr('number'),
genre: DS.belongsTo('genre')
});
App.Genre = DS.Model.extend({
name: DS.attr(),
books: DS.hasMany('book', {async: true})
});
App.ApplicationAdapter = DS.FixtureAdapter.extend();
App.Todo = DS.Model.extend({
title: DS.attr('string'),
isCompleted: DS.attr('boolean')
});
App.Todo.FIXTURES = [
{ id: 1, title: 'Learn Ember.js', isCompleted: false },
{ id: 2, title: 'Work for Avenue Code', isCompleted: true },
{ id: 3, title: 'Learn Javascript', isCompleted: true }
];
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api/1',
host: 'http://api.example.com'
});
store.find('user', 1).then(function(user){});
App.BooksController = Ember.ArrayController.extend({
sortProperties: ['title'],
sortAscending: false
});
App.ReviewsNewController = Ember.Controller.extend({
actions: {
createReview: function(){
var controller = this;
this.get('model').save().then(function(){
controller.transitionToRoute('index');
});
}
}
});
<script type="text/x-handlebars" data-template-name="reviews/new">
<button type="submit" {{action 'createReview'}}>Save Review</button>
</script>
var view = Ember.View.create({
templateName: 'say-hello',
name: "Bob"
});
<script type="text/x-handlebars" data-template-name="say-hello">
Hello, <b>{{view.name}}</b>
</script>
App.ClickableView = Ember.View.extend({
click: function(event) {
this.get('controller').send('turnItUp', 11);
}
});
App.PlaybackController = Ember.ObjectController.extend({
actions: {
turnItUp: function(level){ /*Do your thing*/ }
}
});
{{#view "clickable"}}
This is a clickable area!
{{/view}}
<script type="text/x-handlebars-template" data-template-name='book'>
{{book-details book=this tag='div' class='row'}}
</script>
<script type="text/x-handlebars-template" data-template-name='components/book-details'>
<img {{bind-attr src='book.image'}} />
</script>