Skip to content

Commit b7e5c12

Browse files
authored
Update README.md
1 parent 38623b1 commit b7e5c12

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

README.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ Convert large amounts of data array to nested data structure fastly!<br />
44
Use the test data that array length 46086, just take about 0.1 second.<br />
55
<br />
66
快速地转换数据量比较大的数组为树结构,转换数组长度为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
1012
```
11-
# Example
1213
```javascript
1314
var smartArrayToTree = require('../index.js');
1415
var fetch = require('node-fetch');
@@ -29,6 +30,26 @@ fetch('https://raw.githubusercontent.com/internet5/smart-array-to-tree/master/ex
2930
//2017-11-21T09:51:37.930Z
3031
//2017-11-21T09:51:37.979Z
3132
```
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+
```
3253
## API
3354
### `smartArrayToTree(data, [options])`
3455
Convert a plain array of nodes (with pointers to parent nodes) to a a nested data structure.

0 commit comments

Comments
 (0)