Interface between a dijit.Tree and a dojo.data store that doesn't have a root item, a.k.a. a store that has multiple "top level" items.
Use this class to wrap a dojo.data store, making all the items matching the specified query appear as children of a fabricated "root item". If no query is specified then all the items returned by fetch() on the underlying store become children of the root item. This class allows dijit.Tree to assume a single root item, even if the store doesn't have one.
When using this class the developer must override a number of methods according to their app and data, including:
Parameter | Type | Description |
---|---|---|
params | undefined |
See the dijit/tree/ForestStoreModel reference documentation for more information.
One or more attribute names (attributes in the dojo.data item) that specify that item's children
Setting this to true will cause the TreeStoreModel to defer calling loadItem on nodes until they are expanded. This allows for lazying loading where only one loadItem (and generally one network call, consequently) per expansion (rather than one for each child). This relies on partial loading of the children items; each children item of a fully loaded item should contain the label and info about having children.
If specified, get label for tree node from this attribute, rather than by calling store.getLabel()
Name of attribute in the Object passed to newItem() that specifies the id.
If newItemIdAttr is set then it's used when newItem() is called to see if an item with the same id already exists, and if so just links to the old item (so that the old item ends up with two parents).
Setting this to null or "" will make every drop create a new item.
Parameter | Type | Description |
---|---|---|
keywordArgs | object |
Calls onComplete() with array of child items of given parent item, all loaded.
Parameter | Type | Description |
---|---|---|
parentItem | dojo/data/Item | |
callback | function(items) | |
onError | function |
Calls onItem with the root item for the tree, possibly a fabricated item. Calls onError on error.
Parameter | Type | Description |
---|---|---|
onItem | undefined | |
onError | undefined |
Parameter | Type | Description |
---|---|---|
something | anything |
Tells if an item has or may have children. Implementing logic here avoids showing +/- expando icon for nodes that we know don't have children. (For efficiency reasons we may not want to check if an element actually has children until user clicks the expando node)
Parameter | Type | Description |
---|---|---|
item | dojo/data/Item |
Creates a new item. See dojo/data/api/Write for details on args. Used in drag & drop when item from external source dropped onto tree.
Parameter | Type | Description |
---|---|---|
args | dijit/tree/dndSource.__Item | |
parent | Item | |
insertIndex | int |
Optional
|
Move or copy an item from one parent item to another. Used in drag & drop
Parameter | Type | Description |
---|---|---|
childItem | Item | |
oldParentItem | Item | |
newParentItem | Item | |
bCopy | Boolean | |
insertIndex | int |
Optional
|
Called when item added to root of tree; user must override this method to modify the item so that it matches the query for top level items
Parameter | Type | Description |
---|---|---|
item | item |
store.setValue(item, "root", true);
Callback whenever an item has changed, so that Tree can update the label, icon, etc. Note that changes to an item's children or parent(s) will trigger an onChildrenChange() so you can ignore those changes here.
Parameter | Type | Description |
---|---|---|
item | dojo/data/Item |
store.setValue(item, "root", true);
Callback to do notifications about new, updated, or deleted items.
Parameter | Type | Description |
---|---|---|
parent | dojo/data/Item | |
newChildrenList | dojo/data/Item[] |
store.setValue(item, "root", true);
Callback when an item has been deleted.
Note that there will also be an onChildrenChange() callback for the parent of this item.
Parameter | Type | Description |
---|---|---|
item | dojo/data/Item |
store.setValue(item, "root", true);
Handler for delete notifications from underlying store
Parameter | Type | Description |
---|---|---|
item | Object |
store.setValue(item, "root", true);
Called when item removed from root of tree; user must override this method to modify the item so it doesn't match the query for top level items
Parameter | Type | Description |
---|---|---|
item | item |
store.unsetAttribute(item, "root");
Handler for when new items appear in the store. Developers should override this method to be more efficient based on their app/data.
Note that the default implementation requeries the top level items every time a new item is created, since any new item could be a top level item (even in addition to being a child of another item, since items can have multiple parents).
If developers can detect which items are possible top level items (based on the item and the parentInfo parameters), they should override this method to only call _requeryTop() for top level items. Often all top level items have parentInfo==null, but that will depend on which store you use and what your data is like.
Parameter | Type | Description |
---|---|---|
item | dojo/data/api/Item | |
parentInfo | Object |
store.unsetAttribute(item, "root");
User can override this method to modify a new element that's being added to the root of the tree, for example to add a flag like root=true
Parameter | Type | Description |
---|---|---|
args | dijit/tree/dndSource.__Item |
store.unsetAttribute(item, "root");
Updates the tree view according to changes to an item in the data store. Developers should override this method to be more efficient based on their app/data.
Handles updates to an item's children by calling onChildrenChange(), and other updates to an item by calling onChange().
Also, any change to any item re-executes the query for the tree's top-level items, since this modified item may have started/stopped matching the query for top level items.
If possible, developers should override this function to only call _requeryTop() when the change to the item has caused it to stop/start being a top level item in the tree.
Parameter | Type | Description |
---|---|---|
item | item | |
attribute | attribute-name-string | |
oldValue | Object | Array | |
newValue | Object | Array |
store.unsetAttribute(item, "root");