Print Friendly

Class Ext.tree.TreeLoader

Package:Ext.tree
Class:TreeLoader
Extends:Observable
Defined In:TreeLoader.js
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

Method Defined By
  TreeLoaderObject config ) TreeLoader
Creates a new Treeloader.
  addEventsObject object ) : void Observable
Used to define events on this Observable
  addListenerString 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
  fireEventString eventName, Object... args ) : Boolean Observable
Fires the specified event with the passed parameters (minus the event name).
  hasListenerString eventName ) : Boolean Observable
Checks to see if this object has any listeners for a specified event
  loadExt.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...
  onString 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
  removeListenerString eventName, Function handler, [Object scope] ) : void Observable
Removes a listener
  unString eventName, Function handler, [Object scope] ) : void Observable
Removes a listener (shorthand for removeListener)

Public Events

Event Defined By
  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

Config Options Defined By
  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.
Parameters:
  • config : Object
    A config object containing config properties.

Method Details

addEvents

public function addEvents( Object object )
Used to define events on this Observable
Parameters:
  • object : Object
    The object with the events defined
Returns:
  • void
This method is defined by Observable.

addListener

public function addListener( String eventName, Function handler, [Object scope], [Object options] )
Appends an event handler to this component
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The 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:
  • void
This method is defined by Observable.

createNode

public function createNode()
Override this function for custom TreeNode node implementation
Parameters:
  • None.
Returns:
  • void
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).
Parameters:
  • eventName : String
  • args : Object...
    Variable number of parameters are passed to handlers
Returns:
  • Boolean
    returns false if any of the handlers return false otherwise it returns true
This method is defined by Observable.

hasListener

public function hasListener( String eventName )
Checks to see if this object has any listeners for a specified event
Parameters:
  • eventName : String
    The name of the event to check for
Returns:
  • Boolean
    True if the event is being listened for, else false
This method is defined by Observable.

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.TreeNode
  • callback : Function
Returns:
  • void
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 : String
    The type of event to listen for
  • handler : Function
    The 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:
  • void
This method is defined by Observable.

purgeListeners

public function purgeListeners()
Removes all listeners for this object
Parameters:
  • None.
Returns:
  • void
This method is defined by Observable.

removeListener

public function removeListener( String eventName, Function handler, [Object scope] )
Removes a listener
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The handler to remove
  • scope : Object
    (optional) The scope (this object) for the handler
Returns:
  • void
This method is defined by Observable.

un

public function un( String eventName, Function handler, [Object scope] )
Removes a listener (shorthand for removeListener)
Parameters:
  • eventName : String
    The type of event to listen for
  • handler : Function
    The handler to remove
  • scope : Object
    (optional) The scope (this object) for the handler
Returns:
  • void
This method is defined by Observable.

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 : Object
    TreeLoader object.
  • node : Object
    The Ext.tree.TreeNode object being loaded.
  • callback : Object
    The 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 : Object
    TreeLoader object.
  • node : Object
    The Ext.tree.TreeNode object being loaded.
  • response : Object
    The response object containing the data from the server.
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 : Object
    TreeLoader object.
  • node : Object
    The Ext.tree.TreeNode object being loaded.
  • response : Object
    The response object containing the data from the server.
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.

Ext - Copyright © 2006-2007 Ext JS, LLC
All rights reserved.