On Github davidatkinsondoyle / introToEmber
App.Person = Ember.Object.extend({
say: function(thing) {
var name = this.get('name');
alert(name + " says: " + thing);
}
});
var person = App.Person.create();
person.say("Hello"); // alerts " says: Hello"
App.Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
var ironMan = App.Person.create({
firstName: "Tony",
lastName: "Stark"
});
ironMan.get('fullName'); // "Tony Stark"
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');
return firstName + ' ' + lastName;
}.property('firstName', 'lastName'),
fullNameChanged: function() {
// deal with the change
}.observes('fullName').on('init')
});
var person = Person.create({
firstName: 'Yehuda',
lastName: 'Katz'
});
person.set('firstName', 'Brohuda'); // observer will fire
<script type="text/x-handlebars">
Hello, <strong>{{firstName}} {{lastName}}</strong>!
</script>
<script type="text/x-handlebars">
<div>
{{outlet}}
</div>
</script>
Left Column
Right Column
App.Router.map(function() {
this.route("about", { path: "/about" });
this.route("favorites", { path: "/favs" });
});
- Router Defines the whole architecture of the appApp.Router.map(function() {
this.resource('posts', { path: '/posts' }, function() {
this.resource('post', { path: '/post/:post_id' });
});
});
- defined my the model
- updates url with id:property App.PersonsRoute = Ember.Route.extend({
model: function() {
return App.persons.getPersons();
},
setupController: function(controller, model) {
controller.set('model', model);
},
beforeModel: function(transition) {
if (!App.Persons) {
return Ember.$.getScript('/models/persons.js');
}
}
afterModel: function(posts, transition) {
if (persons.get('length') === 1) {
this.transitionTo('persons.show', persons.get('firstObject'));
}
}
});
- model can be promise or sync
- setupController is defult model=modelMost simple controller, when there is no model.
...
...
Used when model is an object
Has no additional methods Controller checks its own properties before it checks the modelUsed when model is an Array (enumerable)