dijit/tree/ObjectStoreModel (version 1.10)

dijit/Destroyable

Summary

Implements dijit/tree/model connecting dijit/Tree to a dojo/store/api/Store that implements getChildren().

If getChildren() returns an array with an observe() method, then it will be leveraged to reflect store updates to the tree. So, this class will work best when:

1. the store implements dojo/store/Observable
2. getChildren() is implemented as a query to the server (i.e. it calls store.query())

Drag and Drop: To support drag and drop, besides implementing getChildren() and dojo/store/Observable, the store must support the parent option to put(). And in order to have child elements ordered according to how the user dropped them, put() must support the before option.

Usage

var foo = new ObjectStoreModel(args);
dijit/tree/ObjectStoreModel
Parameter Type Description
args Object

See the dijit/tree/ObjectStoreModel reference documentation for more information.

Property Summary

  • labelAttrGet label for tree node from this attribute
  • labelTypeSpecifies how to interpret the labelAttr in the data store items.
  • querySpecifies datastore query to return the root item for the tree.
  • rootPointer to the root item from the dojo/store/api/Store (read only, not a parameter)
  • storeUnderlying store

Method Summary

  • destroy(preserveDom) Destroy this class, releasing any resources registered via own().
  • getChildren(parentItem,onComplete,onError) Calls onComplete() with array of child items of given parent item.
  • getIdentity(item)
  • getLabel(item) Get the label for an item
  • getRoot(onItem,onError) Calls onItem with the root item for the tree, possibly a fabricated item.
  • isItem(something)
  • mayHaveChildren(item) Tells if an item has or might have children.
  • newItem(args,parent,insertIndex,before) Creates a new item.
  • own() Track specified handles and remove/destroy them when this instance is destroyed, unless they were already removed/destroyed manually.
  • pasteItem(childItem,oldParentItem,newParentItem,bCopy,insertIndex,before) Move or copy an item from one parent item to another.

Event Summary

  • onChange(item) Callback whenever an item has changed, so that Tree can update the label, icon, etc.
  • onChildrenChange(parent,newChildrenList) Callback to do notifications about new, updated, or deleted items.
  • onDelete(item) Callback when an item has been deleted.

Properties

labelAttr

Get label for tree node from this attribute

labelType

Specifies how to interpret the labelAttr in the data store items. Can be "html" or "text".

query

Specifies datastore query to return the root item for the tree. Must only return a single item. Alternately can just pass in pointer to root item.

root

Pointer to the root item from the dojo/store/api/Store (read only, not a parameter)

store

Underlying store

Methods

destroy(preserveDom)
Defined by dijit/Destroyable

Destroy this class, releasing any resources registered via own().

Parameter Type Description
preserveDom Boolean
getChildren(parentItem,onComplete,onError)

Calls onComplete() with array of child items of given parent item.

Parameter Type Description
parentItem Object

Item from the dojo/store

onComplete function(items)
onError function
getIdentity(item)
Parameter Type Description
item item
Returns:undefined
getLabel(item)

Get the label for an item

Parameter Type Description
item dojo/data/Item
Returns:undefined
getRoot(onItem,onError)

Calls onItem with the root item for the tree, possibly a fabricated item. Calls onError on error.

Parameter Type Description
onItem undefined
onError undefined
isItem(something)
Parameter Type Description
something undefined
Returns:boolean
mayHaveChildren(item)

Tells if an item has or might have children. Implementing logic here avoids showing +/- expando icon for nodes that we know won't have children. (For efficiency reasons we may not want to check if an element actually has children until user clicks the expando node).

Application code should override this method based on the data, for example it could be return item.leaf == true;.

Note that mayHaveChildren() must return true for an item if it could possibly have children in the future, due to drag-an-drop or some other data store update. Also note that it may return true if it's just too expensive to check during tree creation whether or not the item has children.

Parameter Type Description
item Object

Item from the dojo/store

Returns:boolean
newItem(args,parent,insertIndex,before)

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
before Item
Returns:undefined
own()
Defined by dijit/Destroyable

Track specified handles and remove/destroy them when this instance is destroyed, unless they were already removed/destroyed manually.

Returns:any | undefined

The array of specified handles, so you can do for example:

var handle = this.own(on(...))[0];
pasteItem(childItem,oldParentItem,newParentItem,bCopy,insertIndex,before)

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
before Item
Returns:instance

Events

onChange(item)

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
onChildrenChange(parent,newChildrenList)

Callback to do notifications about new, updated, or deleted items.

Parameter Type Description
parent dojo/data/Item
newChildrenList Object[]

Items from the store

onDelete(item)

Callback when an item has been deleted. Actually we have no way of knowing this with the new dojo.store API, so this method is never called (but it's left here since Tree connects to it).

Parameter Type Description
item dojo/data/Item
Error in the documentation? Can’t find what you are looking for? Let us know!