-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo5.js
58 lines (51 loc) · 1.67 KB
/
demo5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, {Component} from 'react';
import TreeView, {testdata} from './tree.js';
// Demonstrate a customized body, adding a callback called when clicked.
export default class Demo5 extends Component {
// Here, we need to fetch data from server.
constructor(props) {
super(props);
this.state = {contents: testdata};
}
// The contents has been changed somehow.
onChange(contents) {
console.log("New contents: %o", contents);
}
// User clicked on a node.
onActivate(node) {
console.log("Activated node %o", node);
}
// Function providing the node body, overriding the default plain name.
// - node: object - The actual node. See Data Model in README.md.
// - props: As provided to the Node object.
customBody(node, props) {
const style = {
borderStyle: props.hovered ? 'dotted' : 'none'
};
const callback = function(node) {
this.onActivate(node);
return false;
}.bind(this, node);
return (
<span style={style}>
<a href="#notUsed" onClick={callback}>
{node.name}
</a>
</span>
);
}
render() {
const onChange = function(c) {this.setState({contents: c}); }.bind(this);
return (
<div className="TreeviewDemo">
<TreeView
contents={this.state.contents}
onChange={onChange}
options={{
enableEdit: true,
customBody: this.customBody.bind(this)
}} />
</div>
);
}
}