forked from dojo/dojo1-dstore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tree.js
42 lines (36 loc) · 1.16 KB
/
Tree.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
define([
'dojo/_base/declare'
/*=====, 'dstore/Store'=====*/
], function (declare /*=====, Store=====*/) {
return declare(null, {
constructor: function () {
this.root = this;
},
mayHaveChildren: function (object) {
// summary:
// Check if an object may have children
// description:
// This method is useful for eliminating the possibility that an object may have children,
// allowing collection consumers to determine things like whether to render UI for child-expansion
// and whether a query is necessary to retrieve an object's children.
// object:
// The potential parent
// returns: boolean
return 'hasChildren' in object ? object.hasChildren : true;
},
getRootCollection: function () {
// summary:
// Get the collection of objects with no parents
// returns: dstore/Store.Collection
return this.root.filter({ parent: null });
},
getChildren: function (object) {
// summary:
// Get a collection of the children of the provided parent object
// object:
// The parent object
// returns: dstore/Store.Collection
return this.root.filter({ parent: this.getIdentity(object) });
}
});
});