App.User = Ember.Object.extend({
firstName: 'Hello',
lastName: 'world',
fullName: (function() {
console.log(this.get('firstName'));
console.log(this.get('lastName'));
return this.get('firstName') + " " + this.get('lastName');
}
).property('firstName', 'lastName'),
getFullName: function() {
return this.get('firstName') + " " + this.get('lastName');
},
showMessage: function(message) { alert(message) },
showName: function() { this.showMessage(this.get('fullName')) },
weightChanged: function() {
if (this.get('weight') > 400) alert('yikes')
}.observes('weight'),
bodyObserver: function() {
alert("You've changed. I feel like I don't even know you anymore.")
}.observes('weight', 'height')
})
App.Human = Em.Object.extend();
App.Human.reopen({ name: 'Senor' });
App.Human.reopenClass( {
sayUncle: function() { alert("uncle") }
})
AboutRoute, AboutController, AboutView, and a template named about.js.emblem
Route objects are really all about using hooks to prepare data and perform any setup actions required for the controller.
App.UsersRoute = Ember.Route.extend({
beforeModel: function(transition) { },
model: function(params, transition) { },
afterModel: function(model, transition) { },
activate: function() { },
setupController: function(controller, model) {
controller.set('model', model)
// or this._super(arguments...)
},
deactivate: function() { }
})
the current model for that route
this.modelFor('routeName')
get that controller object
this.controllerFor('controllerName')
Sometimes you may want to get the model for that controller, in which case you would do
this.controllerFor('controllerName').get('model')