-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo4.js
56 lines (49 loc) · 1.75 KB
/
demo4.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
import React, {Component } from 'react'
import TreeView, {testdata} from './tree.js'
// Demonstrate handling of a server not acceptinng bult updates.
export default class Demo2 extends Component {
// Here, we need to fetch data from server.
constructor(props) {
super(props);
this.state = {contents: testdata};
}
// A node is moved.
// - newParent: Parent for the moved node, with re-arranged
// children list.
// - oldParent: The moved node's previous parent.
onMoveNode(newParent, oldParent) {
console.log("Shuffled children in %o:" , newParent);
console.log("Possibly one child moved from %o:" , oldParent);
}
// User edited node data.
// - id changed node id.
// - data: object. By default, only the name property is defined,
// but a custom NodeEditForm might add more properties.
onEdit(id, data) {
console.log("Edited id: " + id + ", new data: %o", data);
}
// User dropped an item in the trash.
onDeleteNode(id) {
console.log("Removed id: " + id);
}
// User added a new node.
// - id (int) Unique id for new node.
// - text(string) new name.
// - nodes: Updated contents, all nodes.
onAddNode(nodes, text, id) {
console.log("Adding node, id: " + id + ", text: " + text
+ ", new length: " + nodes.length);
}
render() {
return (
<div className="TreeviewDemo">
<TreeView
contents={this.state.contents}
onEdit={this.onEdit}
onDeleteNode={this.onDeleteNode}
onMoveNode={this.onMoveNode}
onAddNode={this.onAddNode} />
</div>
);
}
}