@@ -4,11 +4,12 @@ Convert large amounts of data array to nested data structure fastly!<br />
4
4
Use the test data that array length 46086, just take about 0.1 second.<br />
5
5
<br />
6
6
快速地转换数据量比较大的数组为树结构,转换数组长度为46086的组数时,只花了大约0.1秒的时间,而其他转换工具对于这个数据量要么就是转换不正确,要么就是直接挂掉
7
- # Installation
8
- ``` javascript
9
- npm i smart- arraytotree -- save
7
+ # Installation && Usage
8
+
9
+ Using npm:
10
+ ``` shell
11
+ $ npm i smart-arraytotree --save
10
12
```
11
- # Example
12
13
``` javascript
13
14
var smartArrayToTree = require (' ../index.js' );
14
15
var fetch = require (' node-fetch' );
@@ -29,6 +30,26 @@ fetch('https://raw.githubusercontent.com/internet5/smart-array-to-tree/master/ex
29
30
// 2017-11-21T09:51:37.930Z
30
31
// 2017-11-21T09:51:37.979Z
31
32
```
33
+
34
+ In a browser:
35
+ ``` html
36
+ <script src =" smartArrayToTree.js" ></script >
37
+ ```
38
+ ``` html
39
+ <script src =" http://code.jquery.com/jquery-2.2.4.min.js" integrity =" sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
40
+ crossorigin =" anonymous" ></script >
41
+ <script src =" smartArrayToTree.js" ></script >
42
+ <script >
43
+ window .onload = function () {
44
+ $ .getJSON (" https://raw.githubusercontent.com/internet5/smart-array-to-tree/master/example/data.json" , function (data ) {
45
+ console .log (new Date ());
46
+ var tree = smartArrayToTree (data, { id: ' regionId' , pid: ' parentId' , firstPid: null });
47
+ console .log (new Date ());
48
+ console .log (tree)
49
+ });
50
+ }
51
+ </script >
52
+ ```
32
53
## API
33
54
### ` smartArrayToTree(data, [options]) `
34
55
Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.
0 commit comments