Class Ext.tree.TreeLoader
A TreeLoader provides for lazy loading of an
Ext.tree.TreeNode's child
nodes from a specified URL. The response must be a javascript Array definition
who's elements are node definition objects. eg:
[{ 'id': 1, 'text': 'A folder Node', 'leaf': false },
{ 'id': 2, 'text': 'A leaf Node', 'leaf': true }]
A server request is sent, and child nodes are loaded only when a node is expanded.
The loading node's id is passed to the server under the parameter name "node" to
enable the server to produce the correct child nodes.
To pass extra parameters, an event handler may be attached to the "beforeload"
event, and the parameters specified in the TreeLoader's baseParams property:
myTreeLoader.on("beforeload", function(treeLoader, node) {
this.baseParams.category = node.attributes.category;
}, this);
<
This would pass an HTTP parameter called "category" to the server containing
the value of the Node's "category" attribute.
Properties
-
Methods
-
Events
-
Config Options
Public Properties
This class has no public properties.
Public Methods
|
TreeLoader( Object config ) |
TreeLoader |
Creates a new Treeloader. |
|
addEvents( Object object ) : void |
Observable |
Used to define events on this Observable |
|
addListener( String eventName , Function handler , [Object scope ], [Object options ] ) : void |
Observable |
Appends an event handler to this component |
|
createNode() : void |
TreeLoader |
Override this function for custom TreeNode node implementation |
|
fireEvent( String eventName , Object... args ) : Boolean |
Observable |
Fires the specified event with the passed parameters (minus the event name). |
|
hasListener( String eventName ) : Boolean |
Observable |
Checks to see if this object has any listeners for a specified event |
|
load( Ext.tree.TreeNode node , Function callback ) : void |
TreeLoader |
Load an Ext.tree.TreeNode from the URL specified in the constructor.
This is called automatically when a node is expa... |
|
on( String eventName , Function handler , [Object scope ], [Object options ] ) : void |
Observable |
Appends an event handler to this element (shorthand for addListener) |
|
purgeListeners() : void |
Observable |
Removes all listeners for this object |
|
removeListener( String eventName , Function handler , [Object scope ] ) : void |
Observable |
Removes a listener |
|
un( String eventName , Function handler , [Object scope ] ) : void |
Observable |
Removes a listener (shorthand for removeListener) |
Public Events
|
beforeload : ( Object This , Object node , Object callback ) |
TreeLoader |
Fires before a network request is made to retrieve the Json text which specifies a node's children. |
|
load : ( Object This , Object node , Object response ) |
TreeLoader |
Fires when the node has been successfuly loaded. |
|
loadexception : ( Object This , Object node , Object response ) |
TreeLoader |
Fires if the network request failed. |
Config Options
|
baseAttrs : Object |
TreeLoader |
(optional) An object containing attributes to be added to all nodes created by this loader. If the attributes sent by... |
|
baseParams : Object |
TreeLoader |
(optional) An object containing properties which specify HTTP parameters to be passed to each request for child nodes. |
|
clearOnLoad : Boolean |
TreeLoader |
(optional) Default to true. Remove previously existing child nodes before loading. |
|
dataUrl : String |
TreeLoader |
The URL from which to request a Json string which specifies an array of node definition object representing the child... |
|
uiProviders : Object |
TreeLoader |
(optional) An object containing properties which specify custom Ext.tree.TreeNodeUI implementations. If the optional ... |
Constructor Details
TreeLoader
public function TreeLoader( Object config
)
Creates a new Treeloader.
Method Details
addEvents
public function addEvents( Object object
)
Used to define events on this Observable
addListener
public function addListener( String eventName
, Function handler
, [Object scope
], [Object options
] )
Appends an event handler to this component
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope in which to execute the handler
function. The handler function's "this" context.
options
: Object(optional) An object containing handler configuration
properties. This may contain any of the following properties:
- scope {Object} The scope in which to execute the handler function. The handler function's "this" context.
- delay {Number} The number of milliseconds to delay the invocation of the handler after te event fires.
- single {Boolean} True to add a handler to handle just the next firing of the event, and then remove itself.
- buffer {Number} Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed
by the specified number of milliseconds. If the event fires again within that time, the original
handler is not invoked, but the new handler is scheduled in its place.
Combining Options
Using the options argument, it is possible to combine different types of listeners:
A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
el.on('click', this.onClick, this, {
single: true,
delay: 100,
forumId: 4
});
Attaching multiple handlers in 1 call
The method also allows for a single argument to be passed which is a config object containing properties
which specify multiple handlers.
el.on({
'click': {
fn: this.onClick,
scope: this,
delay: 100
},
'mouseover': {
fn: this.onMouseOver,
scope: this
},
'mouseout': {
fn: this.onMouseOut,
scope: this
}
});
Or a shorthand syntax which passes the same scope object to all handlers:
el.on({
'click': this.onClick,
'mouseover': this.onMouseOver,
'mouseout': this.onMouseOut,
scope: this
});
Returns:
createNode
public function createNode()
Override this function for custom TreeNode node implementation
This method is defined by TreeLoader.
fireEvent
public function fireEvent( String eventName
, Object... args
)
Fires the specified event with the passed parameters (minus the event name).
hasListener
public function hasListener( String eventName
)
Checks to see if this object has any listeners for a specified event
load
public function load( Ext.tree.TreeNode node
, Function callback
)
Load an
Ext.tree.TreeNode from the URL specified in the constructor.
This is called automatically when a node is expanded, but may be used to reload
a node (or append new children if the
clearOnLoad option is false.)
Parameters:
node
: Ext.tree.TreeNodecallback
: Function
Returns:
This method is defined by TreeLoader.
on
public function on( String eventName
, Function handler
, [Object scope
], [Object options
] )
Appends an event handler to this element (shorthand for addListener)
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope in which to execute the handler
function. The handler function's "this" context.
options
: Object(optional)
Returns:
purgeListeners
public function purgeListeners()
Removes all listeners for this object
removeListener
public function removeListener( String eventName
, Function handler
, [Object scope
] )
un
public function un( String eventName
, Function handler
, [Object scope
] )
Removes a listener (shorthand for removeListener)
Event Details
beforeload
public event beforeload
Fires before a network request is made to retrieve the Json text which specifies a node's children.
Subscribers will be called with the following parameters:
This
: ObjectTreeLoader object.
node
: Objectcallback
: ObjectThe callback function specified in the
load call.
This event is defined by TreeLoader.
load
public event load
Fires when the node has been successfuly loaded.
Subscribers will be called with the following parameters:
This event is defined by TreeLoader.
loadexception
public event loadexception
Fires if the network request failed.
Subscribers will be called with the following parameters:
This event is defined by TreeLoader.
Config Details
baseAttrs
baseAttrs : Object
(optional) An object containing attributes to be added to all nodes created by this loader. If the attributes sent by the server have an attribute in this object, they take priority.
This config option is defined by TreeLoader.
baseParams
baseParams : Object
(optional) An object containing properties which specify HTTP parameters to be passed to each request for child nodes.
This config option is defined by TreeLoader.
clearOnLoad
clearOnLoad : Boolean
(optional) Default to true. Remove previously existing child nodes before loading.
This config option is defined by TreeLoader.
dataUrl
dataUrl : String
The URL from which to request a Json string which specifies an array of node definition object representing the child nodes to be loaded.
This config option is defined by TreeLoader.
uiProviders
uiProviders : Object
(optional) An object containing properties which specify custom
Ext.tree.TreeNodeUI implementations. If the optional
uiProvider attribute of a returned child node is a string rather than a reference to a TreeNodeUI implementation, this that string value is used as a property name in the uiProviders object.
This config option is defined by TreeLoader.