Welcome, guest ( Login )

WikiHome » DojoDataUseCases » DataBindingAPI

DataBindingAPI

Version 12, changed by chrism 02/20/2007.   Show version history

dojox.data.bind(...)

dojox.data.bind = function(trigger, source, target) {
    // summary:
    //    Bind a source value to a target value on a trigger event or topic.
    // description:
    //    If 'source' and/or 'target' arguments are not instances of accessor,
    //    instances are created from the arguments using AccessorFactory.createAccessor().
    //    If 'trigger' argument has 'topic' property, the topic is subscribed to bind a value on the topic.
    //    Otherwise, the function or event specified to 'event' property of
    //    'trigger' argument is listened to bind a value.
    //    On the specified event, a value is ontained from the source accessor
    //    and set through the target accessor.
    // trigger:
    //    A event or a topic to bind a value from source to target
    // source:
    //    An accessor for source value or an anonymous object for a accessor
    // target:
    //    An accessor for target value or an anonymous object for a accessor
};

The three arguments to the data.bind() function are anonymous objects.  Different kinds of data binding require different properties for each.  The default binding implementation provides the following types of binding:

JS Data Binding
ItemAttribute?
Property

Variations for XML Data Binding
XMLItemAttribute?
XMLProperty

Variations for Complex Widget Bindings
Combobox
Table
Tree
Chart
See also: DataBindingDeclarativeAPI  - Declarative API's for performing data binding using HTML markup.

Comments
[CM] Should bind() be able to return a reference to the resultant Binding object, so that an unbind() function can be performed on the binding.
 
[CM] Should there be an dojo.data.unbindAll() function?


dojox.data.Property

dojo.declare("dojox.data.Property", dojox.data.Accessor,
    function(args) {
        // summary:
        //    Initialize properties from an anonymous object
        // args:
        //    An anonymous object to initialize properties
    },
    {
    // summary:
    //    A default accessor and base class for other accessors
    // description:
    //    'Property' accessor accesses a property of an object with '_property'
    //    property specifying a dotted notation of descendant property names,
    //    such as "a.b.c", to indenty a descendant property, "object.a.b.c" or
    //    "object["a"]["b"]["c"]".
    //    Property names in the dotted notation may have an array index, such as
    //    "a[0]", to identify an array element, literally, "object.a[0]".
    //    When a notation start with an array index, such as "[0].a" to indentify
    //    an array element of the root object, "object[0].a".
    //    This class also serves as a base class for other accessors, so that
    //    sub-class accessors first access to a property of an object and use it
    //    for further identifying the value off the property.
    //    '_property'
    //        A dotted notation to a descendant property
    getValue: function(arg) {
        // summary:
        //    Return a property value of an object
        // description:
        //    This method first calls the super class's ('Accessor') getValue()
        //    to determine the root object.
        //    Then '_property' is used to indentify the descendant property.
        //    If the root object or an intermediate property (object) has
        //    the getter method for a property name, it is used to get
        //    the property value, otherwise the property is accessed simply as
        //    "object[property_name]".
        //    If a property name have an array index, the property value is
        //    assumed as an array and use the index to indetify an array element.
        // arg:
        //    An default root object
        // returns:
        //    A value found, otherwise 'undefined'
    },
    setValue: function(value, arg) {
        // summary:
        //    Set a property value to an object
        // description:
        //    This method first calls the super class's ('Accessor') getValue()
        //    to determine the root object.
        //    If the root object is not found, this method creates an empty
        //    anonymous object and calls the super class's setValue() to store
        //    the new object.
        //    Then '_property' is used to indetify the lead object for a property
        //    to set a given value ('value').
        //    If an intermediate property (object) does not exist, it creates
        //    an empty anonymous object for the property.
        //    If an object has the setter method for a property, it is used to
        //    set the property value, otherwise the property is accessed simply
        //    as "object[property_name]".
        //    If a property name have an array index, the property value is
        //    assumed as an array and use the index to indetify an array element.
        // value:
        //    A value to set
        // arg:
        //    A default root object
    }
});


dojox.data.Accessor

dojo.declare("dojox.data.Accessor", null,
    function(args) {
        // summary:
        //    Initialize proeprties from an anonymous object
        // description:
        //    If 'accessor' property of 'args' argument is specified, but not
        //    an instance of this class, it is assumed as another anonymous
        //    object to intialize a nested accessor and
        //    AccessorFactory.createAccessor()is called to create an instance of
        //    the nest accessor.
        // args:
        //    An anonymous object to initialize properties
    },
    {
    // summary:
    //    A base class for all accessors
    // description:
    //    Accessors implement getValue() and setValue() methods to access an
    //    underlying value off a root object specified, in a specific way to
    //    the implementation.
    //    Accessors can be nested, so that one accessor provides a value, which
    //    in turn to be used for a root object for another accessor.
    //    As a base class, This class provides the following properties
    //    applicable for all sub-classes.
    //    '_object'
    //        The root object that an accessor starts off to access
    //        an underlying value.
    //    '_accessor'
    //        A nested accessor to be called to obtain the root object
    //        when '_object' property is omitted.
    getValue: function(arg) {
        // summary:
        //    Return a value of an object
        // description:
        //    If '_object' proeprty is specifed, this base class method returns
        //    it.
        //    Otherwise and if '_accessor' property is specified, its getValue()
        //    is called.
        //    Otherwise, this base class method returns 'arg' argument.
        //    Typically, sub-classes's methods first calls this base class method
        //    to determine the root object.
        // arg:
        //    A default root object
        // returns:
        //    A value found, otherwise 'undefined'
    },

    setValue: function(value, arg) {
        // summary:
        //    Set a value to an object
        // description:
        //    If '_accessor' is specified, its setValue() is called.
        //    Otherwise, this base class method throws Error.
        //    Sub-classes's setValue() method may call this method to set a new
        //    value through the nested accessor.
        // value:
        //    A value to set
        // arg:
        //    A default root object
    }
});



dojox.data.AccessorFactory

dojox.data.AccessorFactory = new function() {
    // summary:
    //    A factory to create an accessor from an anonymous object
    // description:
    //    Initializes known accessors.
    //    The order of registered accessors is from general ones to special ones,
    //    so that special accessor is picked up by createAccessor().
    this.registerAccessor = function(type, keyArgs) {
        // summary:
        //    Register an accessor
        // type:
        //    A full qualified class name of the accessor
        // keyArgs:
        //    An array of initializer's argument properties to identify
        //    an accessor type
    };

    this.createAccessor = function(args) {
        // summary:
        //    Create an accessor from an anonymous object
        // description:
        //    If 'args' argument has 'type' property, it is used as a full
        //    qualified class name to create an accessor with 'args' argument.
        //    Otherwise, an accessor type is determined by other proeprties
        //    of 'args' checking if 'args' has all 'keyArgs' properties
        //    registered in '_accessors' property of this class.
        //    This search starts from the tail of '_accessors', so that special
        //    accessor can be picked up on the existence of its key properties.
        //    The default accessor is the first one (Property).
        // args:
        //    An anonymous object to initialize an accessor
        // returns:
        //    An accessor
    };
};

Attachments (0)

  File By Size Attached Ver.