Last active
December 20, 2015 08:49
-
-
Save stravid/6103196 to your computer and use it in GitHub Desktop.
Ember.js Beispiel Anwendung für Screenguide Artikel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App = Ember.Application.create(); | |
App.Project = Ember.Object.extend({ | |
title: null, | |
features: null, | |
estimateSum: function() { | |
var features = this.get('features'); | |
return features.reduce( | |
function(total, feature) { | |
return total + feature.get('estimate'); | |
}, 0); | |
}.property('features.@each.estimate') | |
}); | |
App.Feature = Ember.Object.extend({ | |
title: null, | |
estimate: null | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function () { | |
return [ | |
App.Project.create({ title: '', features: [ | |
App.Feature.create({ title: '', estimate: 2 }), | |
App.Feature.create({ title: 'Feature 1.2', estimate: 5 }) | |
] }), | |
App.Project.create({ title: 'Projekt 2', features: [ | |
App.Feature.create({ title: 'Feature 2.1', estimate: 8 }) | |
] }), | |
App.Project.create({ title: 'Projekt 3', features: [ | |
App.Feature.create({ title: 'Feature 3.1', estimate: 1 }), | |
App.Feature.create({ title: 'Feature 3.2', estimate: 1 }), | |
App.Feature.create({ title: 'Feature 3.3', estimate: 2 }) | |
] }) | |
]; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Ember.js Projekte</title> | |
</head> | |
<body> | |
<script type="text/x-handlebars" id="application"> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" id="index"> | |
<h1>Projekte</h1> | |
<ul> | |
{{#each controller}} | |
<li> | |
<h2> | |
{{title}} (Aufwand gesamt: {{estimate}}) | |
</h2> | |
<ul> | |
{{#each features}} | |
<li> | |
{{title}} (Aufwand: {{estimate}}) | |
</li> | |
{{/each}} | |
</ul> | |
</li> | |
{{/each}} | |
</ul> | |
</script> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.4/handlebars.min.js"></script> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.js"></script> | |
<script type="text/javascript" src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment