1 | var helperCreateTreeFunc = require('./helperCreateTreeFunc')
|
2 |
|
3 | function findTreeItem (parent, obj, iterate, context, path, node, parseChildren, opts) {
|
4 | if (obj) {
|
5 | var item, index, len, paths, nodes, match
|
6 | for (index = 0, len = obj.length; index < len; index++) {
|
7 | item = obj[index]
|
8 | paths = path.concat(['' + index])
|
9 | nodes = node.concat([item])
|
10 | if (iterate.call(context, item, index, obj, paths, parent, nodes)) {
|
11 | return { index: index, item: item, path: paths, items: obj, parent: parent, nodes: nodes }
|
12 | }
|
13 | if (parseChildren && item) {
|
14 | match = findTreeItem(item, item[parseChildren], iterate, context, paths.concat([parseChildren]), nodes, parseChildren, opts)
|
15 | if (match) {
|
16 | return match
|
17 | }
|
18 | }
|
19 | }
|
20 | }
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var findTree = helperCreateTreeFunc(findTreeItem)
|
33 |
|
34 | module.exports = findTree
|