Skip to content

Commit

Permalink
Add add tree button to demo page.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverghese committed Feb 7, 2015
1 parent 0d6a6a2 commit 3cba3c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions index.html
Expand Up @@ -2,11 +2,20 @@
<head>
<title>TreeBrowser Component</title>
<link rel="stylesheet" href="css/tree-browser.css">
<style type="text/css">
/* Demo Styles */
.tree-container {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>Tree Browser</h1>
<button id="changeDataButton">Change Data</button>
<div id="treeContainer"></div>
<button id="addTreeButton">Add tree</button>
<p></p>
<div class="tree-container" id="treeContainer"></div>
<div class="tree-container" id="treeContainer2"></div>
<!-- include react -->
<script src="lib/react/react.js"></script>
<script src="lib/react/JSXTransformer.js"></script>
Expand All @@ -23,10 +32,18 @@ <h1>Tree Browser</h1>

$("#changeDataButton").click(function() {
$.getJSON("sample-data/tree2.json")
.then(function(data) {
treeBrowser.setData(data);
});
.then(function(data) {
treeBrowser.setData(data);
});
});

$("#addTreeButton").click(function() {
$(this).hide();
$.getJSON("sample-data/tree2.json")
.then(function(data) {
TreeBrowser.create('#treeContainer2', data);
});
})
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions src/tree-browser.jsx
Expand Up @@ -31,7 +31,7 @@ var TreeBrowser = (function () {
*/
var TreeBrowser = React.createClass({
getInitialState: function () {
return { data: [] };
return this.props.data;
},
/**
* Method to update tree data after render.
Expand Down Expand Up @@ -140,7 +140,7 @@ var TreeBrowser = (function () {
* @return {TreeBrowser}
*/
create: function(cssSelector, data) {
data = data || {};
data = { data: data || [] };
return React.render(
<TreeBrowser data={data} />,
$(cssSelector)[0]
Expand Down

0 comments on commit 3cba3c4

Please sign in to comment.