EMBER WORKSHOP: Bindings
Bindings
HTML
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://builds.emberjs.com/release/ember.js"></script>
JavaScript
// Bindings
App = Ember.Application.create({});
App.DefaultPlayer = Ember.Object.extend({
init: function () {
this.set('imgProfilePrefix', 'default_');
this.set('imgProfileSuffix', '_profile');
},
name: "Steve", // one way to handle default
baseDir: "/images",
imgName: function(){
return this.get('imgProfilePrefix') + this.get('name').split(' ').join('_').toLowerCase() + this.get('imgProfileSuffix') + '.png';
}, // see no property method ... so call is different below
imgPath: function(){
return this.get('baseDir') + '/profile/' + this.imgName();
}.property('baseDir', 'imgName'),
onlineStatusChanged: function(){
console.log('onlineStatusChanged to: ' + this.get('isOnline'));
}.observes('isOnline').on('init')
});
var steve = App.DefaultPlayer.create({
'isOnline': true
});
steve.set('isOnline', false);