Created
February 5, 2013 11:30
-
-
Save radmiraal/4713873 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Node = Ember.Object.extend({ | |
name: null, | |
children: [] | |
}); | |
App.TreeNodeView = Ember.View.extend({ | |
templateName: 'node-template', | |
classNameBindings: ['isOpen', 'hasChildren'] | |
}); | |
App.TreeView = Ember.CollectionView.extend({ | |
tagName: 'ul', | |
classNames: ['tree'], | |
controller: Ember.ArrayController.extend(), | |
itemViewClass: App.TreeNodeView | |
}); | |
App.Tree1Controller = Ember.ArrayController.create({ | |
content: [] | |
}); | |
App.Tree1Controller.pushObject(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: [] | |
}) | |
] | |
})); | |
App.Tree1 = App.TreeView.extend({ | |
content: App.Tree1Controller | |
}); |
This file contains hidden or 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> | |
<title>Ember Tree Component</title> | |
<meta charset="UTF-8"> | |
<script src="Resources/Public/Library/jquery-1.8.2.min.js"></script> | |
<script src="Resources/Public/Library/emberjs/handlebars-1.0.0.beta.6.js"></script> | |
<script src="Resources/Public/Library/emberjs/ember-1.0.0-pre.4.js"></script> | |
<script src="Resources/Public/JavaScript/app.js"></script> | |
<link rel="stylesheet" href="Resources/Public/Library/bootstrap/css/bootstrap.min.css" /> | |
<link rel="stylesheet" href="Resources/Public/Library/bootstrap/css/bootstrap-responsive.min.css" /> | |
<link rel="stylesheet" href="Resources/Public/StyleSheets/style.css" /> | |
</head> | |
<body> | |
<script type="text/x-handlebars" data-template-name="application"> | |
<section class="well"> | |
<header>App.Tree1</header> | |
<div> | |
{{view App.Tree1}} | |
</div> | |
</section> | |
</script> | |
<script type="text/x-handlebars" data-template-name="node-template"> | |
{{view.content.name}} | |
{{#collection contentBinding="view.content.children"}} | |
{{view.content.name}} | |
{{#if view.content.children}} | |
children | |
{{/if}} | |
{{#with view.content}} | |
<div style="margin-left: 18px;">{{view App.TreeNodeView}}</div> | |
{{/with}} | |
{{/collection}} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment