dijit/tree/TreeStoreModel (version 1.10)

Summary

Implements dijit/Tree/model connecting to a dojo.data store with a single root item. Any methods passed into the constructor will override the ones defined here.

Usage

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

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

Property Summary

  • childrenAttrsOne or more attribute names (attributes in the dojo.data item) that specify that item's children
  • deferItemLoadingUntilExpandSetting this to true will cause the TreeStoreModel to defer calling loadItem on nodes until they are expanded.
  • labelAttrIf specified, get label for tree node from this attribute, rather than by calling store.getLabel()
  • newItemIdAttrName of attribute in the Object passed to newItem() that specifies the id.
  • querySpecifies datastore query to return the root item for the tree.
  • rootPointer to the root item (read only, not a parameter)
  • storeUnderlying store

Method Summary

  • destroy()
  • fetchItemByIdentity(keywordArgs) Given the identity of an item, this method returns the item that has that identity through the onItem callback.
  • getChildren(parentItem,onComplete,onError) Calls onComplete() with array of child items of given parent item, all loaded.
  • 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 may have children.
  • newItem(args,parent,insertIndex) Creates a new item.
  • pasteItem(childItem,oldParentItem,newParentItem,bCopy,insertIndex) 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.
  • onDeleteItem(item) Handler for delete notifications from underlying store
  • onNewItem(item,parentInfo) Handler for when new items appear in the store, either from a drop operation or some other way.
  • onSetItem(item,attribute,oldValue,newValue) Updates the tree view according to changes in the data store.

Properties

childrenAttrs

One or more attribute names (attributes in the dojo.data item) that specify that item's children

deferItemLoadingUntilExpand

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.

labelAttr

If specified, get label for tree node from this attribute, rather than by calling store.getLabel()

newItemIdAttr

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.

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 (read only, not a parameter)

store

Underlying store

Methods

destroy()
fetchItemByIdentity(keywordArgs)

Given the identity of an item, this method returns the item that has that identity through the onItem callback. Conforming implementations should return null if there is no item with the given identity. Implementations of fetchItemByIdentity() may sometimes return an item from a local cache and may sometimes fetch an item from a remote server.

Parameter Type Description
keywordArgs object
getChildren(parentItem,onComplete,onError)

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

Parameter Type Description
parentItem dojo/data/Item
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 anything
Returns:undefined
mayHaveChildren(item)

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
Returns:undefined
newItem(args,parent,insertIndex)

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.

Developers will need to override this method if new items get added to parents with multiple children attributes, in order to define which children attribute points to the new item.

Parameter Type Description
args dijit/tree/dndSource.__Item
parent dojo/data/api/Item
insertIndex int
Optional
pasteItem(childItem,oldParentItem,newParentItem,bCopy,insertIndex)

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

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 dojo/data/Item[]
onDelete(item)

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
onDeleteItem(item)

Handler for delete notifications from underlying store

Parameter Type Description
item Object
onNewItem(item,parentInfo)

Handler for when new items appear in the store, either from a drop operation or some other way. Updates the tree view (if necessary).

If the new item is a child of an existing item, calls onChildrenChange() with the new list of children for that existing item.

Parameter Type Description
item dojo/data/Item
parentInfo Object
onSetItem(item,attribute,oldValue,newValue)

Updates the tree view according to changes in the data store.

Handles updates to an item's children by calling onChildrenChange(), and other updates to an item by calling onChange().

See onNewItem for more details on handling updates to an item's children.

Parameter Type Description
item Item
attribute undefined
oldValue Object | Array
newValue Object | Array
Error in the documentation? Can’t find what you are looking for? Let us know!