-
-
Save ticking-clock/6295414 to your computer and use it in GitHub Desktop.
Simple Ember component example
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script> | |
<script src="http://builds.emberjs.com/ember-latest.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<ul> | |
{{#each}} | |
{{person-info person=this}} | |
{{/each}} | |
</ul> | |
</script> | |
<script type="text/x-handlebars" data-template-name="components/person-info"> | |
<h3>{{person.name}}</h3> | |
{{#if person.children}} | |
<ul> | |
{{#each person.children}} | |
{{person-info person=this}} | |
{{/each}} | |
</ul> | |
{{/if}} | |
</script> | |
</body> | |
</html> |
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(); | |
var people = [ | |
{ | |
name: "Gary Bernhardt", | |
children: [{ | |
name: "Bernadette Peters" | |
}, { | |
name: "Peter Pan", | |
children: [{ | |
name: "Captain Hook" | |
}, { | |
name: "Smee" | |
}] | |
}] | |
}, | |
{ | |
name: "Tom Dale", | |
children: [{ | |
name: "Wycats" | |
}] | |
}]; | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
return people; | |
} | |
}); | |
App.PersonInfoComponent = Ember.Component.extend({ | |
tagName: 'li' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment