Ember Binding Objects
Trying out the Bindings in Ember
by amindunited
HTML
<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script>
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>
<script type="text/x-handlebars" data-template-name="application">
<h1>I'm the start of the application template</h1>
</script>
JavaScript
$(function(){
window.MyApp = Em.Application.create({
templateName: "applicaton",
autoInit: false
})
MyApp.ApplicationController = Em.Controller.extend();
MyApp.ApplicationView = Em.View.extend()
MyApp.router = Em.Router.create({
enableLogging: true,
root: Em.Route.extend({
index: Em.Route.extend({
route:'/',
enter:function(){
//MyApp.FirstObj.set('myProps', 'hidleberg')
},
connectOutlets:function(router, context){
}
})
})
})
MyApp.Coffee = Em.Object.extend({})
MyApp.Coffees = Em.Object.create({
content: [],
propsChanged: function(var1, var2){
console.log("props changed within firstObj", var1, var2);
console.log(var1.content);
}.observes('this.content')
})
MyApp.CoffeesController = Em.ArrayController.extend({
contentBinding: 'MyApp.Coffees.content',
init: function(){
var url = "http://picasaweb.google.com/data/feed/api/user/buckley.robin/albumid/5751950773409336513" + '' +'?alt=json&thumbsize=' + '200';
var self = this;
$.getJSON(url, function(data){
var newCoffees = Em.A();
data.feed.entry.forEach(function(item){
var _date = new Date(parseInt(item.gphoto$timestamp.$t));
_date = _date.toDateString();
newCoffees.addObject(MyApp.Coffee.create({
url:item.content.src,
date:_date,//item.gphoto$timestamp.$t,
title:item.title.$t
}))
})
self.set('content', newCoffees)
console.log('self.content = ', self.content);
})
}
})
/*
MyApp.SecondObj = Em.Object.create({
...