Skip to content

Instantly share code, notes, and snippets.

@scottburton11
Created December 15, 2011 03:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottburton11/1479734 to your computer and use it in GitHub Desktop.
Save scottburton11/1479734 to your computer and use it in GitHub Desktop.
Ember.js tree
<html>
<head>
<script src="javascripts/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="javascripts/ember.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
App = Ember.Application.extend();
App.Node = Ember.Object.extend({
name: null,
children: []
});
App.tree = App.Node.create({
name: "Node 1",
children: [
App.Node.create({
name: "Node 2",
children: [
App.Node.create({
name: "Leaf 2",
children: []
})
]
}),
App.Node.create({
name: "Leaf 1",
children: []
})
]
});
</script>
<script type='text/x-handlebars' data-template-name='node-template'>
<div>Name: {{name}}</div>
<div>
{{#each children}}
{{#with this}}
<div style="margin-left: 18px;">{{view App.nodeView }}</div>
{{/with}}
{{/each}}
</div>
</script>
<script type="text/javascript" charset="utf-8">
App.nodeView = Ember.View.extend({
templateName: 'node-template'
});
$(function(){
var root = App.nodeView.create({
name: App.tree.get("name"),
children: App.tree.get("children")
});
root.append();
});
</script>
</head>
<body>
</body>
</html>
@sebastianseilund
Copy link

If anybody is interested in a newer example, check out this post: http://billysbilling.com/blog/How-to-implement-a-tree-in-Ember-js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment