-
-
Save beatsm/342be3fcf43c2d698dfefb95bdd9e9b2 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
<template> | |
<require from="tree-node"></require> | |
<tree-node repeat.for="node of locations" current.bind="node"></tree-node> | |
<button click.trigger="addCardiff()" class="btn btn-default">Add Cardiff</button> | |
<button click.trigger="addBristol()" class="btn btn-default">Add Bristol</button> | |
</template> |
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
3d import {NodeModel} from "node-model"; | |
export class App { | |
private locations: NodeModel[]; | |
constructor() { | |
this.locations = []; | |
var texas = new NodeModel('Texas', | |
[new NodeModel('Houston', []), | |
new NodeModel('Austin', [])]); | |
console.log(JSON.stringify(texas)); | |
this.locations = [texas]; | |
} | |
addCardiff(): void { | |
var cardiff = new NodeModel('Cardiff', | |
[new NodeModel('Cardiff Bay', [])]); | |
this.locations.push(cardiff); | |
} | |
addBristol(): void { | |
var bristol = `{"name":"Bristol","children": | |
[{"name":"Easton","children":[],"visible":true}, | |
{"name":"Eastville","children":[],"visible":true}], | |
"visible":true,"icon":"fa fa-chevron-down","expanded":true}`; | |
var d = JSON.parse(bristol); | |
this.locations.push(d); | |
} | |
} |
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>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
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
export class NodeModel { | |
public name: string; | |
public visible: boolean; | |
public children: NodeModel[]; | |
public expanded: boolean; | |
public icon: string; | |
constructor(name: string, children: NodeModel[]) | |
{ | |
this.name = name; | |
this.children = children || []; | |
this.visible = true; | |
if (this.hasChildren()) { | |
this.icon = "fa fa-chevron-down"; | |
this.expanded = true; | |
} | |
} | |
hasChildren(): boolean { | |
return this.children.length > 0; | |
} | |
toggleNode(): void { | |
for (var i: number = 0; i < this.children.length; i++) { | |
this.children[i].visible = !this.children[i].visible; | |
} | |
this.expanded = !this.expanded; | |
if (this.expanded === true) { | |
this.icon = "fa fa-chevron-down"; | |
} else { | |
this.icon = "fa fa-chevron-right"; | |
} | |
} | |
} |
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
<template> | |
<ul show.bind="current.visible" style="list-style-type: none;"> | |
<li> | |
<div> | |
<span if.bind="current.hasChildren()" click.trigger="current.toggleNode()" class="${current.icon}"></span> | |
<span>${current.name}</span> | |
</div> | |
<tree-node repeat.for="node of current.children" current.bind="node"></tree-node> | |
</li> | |
</ul> | |
</template> |
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
import {bindable} from 'aurelia-framework'; | |
export class TreeNode { | |
@bindable current = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment