-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo3.js
64 lines (59 loc) · 2.1 KB
/
demo3.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
59
60
61
62
63
64
import React, {Component} from 'react';
import TreeView, {testdata} from './tree.js';
// Demonstrate a customized edit form with a user-defined property.
export default class Demo3 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);
}
// Function providing a form to edit a node's properties.
// - node: object - The actual node. See Data Model in README.md.
// - onEdit: function(node) - callback to invoke when a node's
// properties are changed.
editForm(node, onEdit) {
const outerStyle = {display: 'inline-block'};
const nameCallback = function(node, event) {
node.name = event.target.value;
onEdit(node);
}.bind(null, node);
const myValue = node.myValue ? node.myValue : false;
const myCallback = function(node, event) {
node.myValue = event.target.checked;
onEdit(node);
}.bind(null, node);
return (
<span style={outerStyle}>
<form>
<input
type="text"
value={node.name}
onChange={nameCallback} />
<br />
{'My own property'}
<input
type="checkbox"
name="myValue"
value={myValue}
checked={myValue}
onChange={myCallback} />
</form>
</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, editForm: this.editForm}} />
</div>
);
}
}