Class: ArrayModel

system.models.arrays. ArrayModel


new ArrayModel()

This model use an internal Array to register objects.

Implements:
Example
var o1 = { id : "key1" } ;
var o2 = { id : "key2" } ;
var o3 = { id : "key3" } ;
var o4 = { id : "key4" } ;
var o5 = { id : "key5" } ;
var o6 = { id : "key6" } ;

var model = new ArrayModel();

var added = function( index , value , model )
{
    trace( model + " added(" + index + ") value:" + dump(value) ) ;
}

var beforeChanged = function( value , model )
{
    trace( "[-] before:" + value + " current:" + dump(model.current) + " size:" + model.length ) ;
}

var changed = function( value , model )
{
    trace( "[+] change:" + value + " current:" + dump(model.current) + " size:" + model.length ) ;
}

var cleared = function( model )
{
    trace( "[x] clear current:" + dump(model.current) + " size:" + model.length ) ;
}

var removed = function( index , old , model )
{
    trace( model + " removed(" + index + ") old:" + dump(old) ) ;
}

var updated = function( index , old , model )
{
    trace( model + " updated(" + index + ") old:" + dump(old) ) ;
}

model.added.connect( added ) ;
model.beforeChanged.connect( beforeChanged ) ;
model.changed.connect( changed ) ;
model.cleared.connect( cleared ) ;
model.removed.connect( removed ) ;
model.updated.connect( updated ) ;

model.add( o1 ) ;
model.add( o2 ) ;
model.add( o3 ) ;
model.add( o4 ) ;
model.add( o5 ) ;
model.add( o6 ) ;

trace( "model length:" + model.length ) ;

trace( "model.get(0) == o1 : " + dump( model.get(0)) ) ;
trace( "model.get(1) == o4 : " + dump( model.get(1)) ) ;

model.updateAt( 0 , o4 ) ;
trace( "model.get(0) == o1 : " + dump( model.get(0)) ) ;

model.current = o1 ;
model.current = o2 ;

model.removeAt( 0 ) ;
model.removeAt( 0 , 2 ) ;
model.remove( o6 ) ;

trace( "model length:" + model.length ) ;

model.clear() ;

Extends

Members


<constant> added :system.signals.Signal

Emits a message when an entry is added in the model.

Type:

<constant> beforeChanged :system.signals.Signal

Emits a message before the current object in the model is changed.

Type:
Inherited From:

<constant> changed :system.signals.Signal

Emits a message when the current object in the model is changed.

Type:
Inherited From:

<constant> cleared :system.signals.Signal

Emits a message when the current object in the model is cleared.

Type:
Inherited From:

current

Determinates the current selected value in this model.

Inherited From:

<readonly> length :number

Indicates the number of elements register in the model.

Type:
  • number

<constant> removed :system.signals.Signal

Emits a message when an entry is removed in the model.

Type:

security :boolean

This property defined if the current property can accept the same object in argument as the current one.

Type:
  • boolean
Inherited From:
Default Value:
  • true

<constant> updated :system.signals.Signal

Emits a message when an entry is updated in the model.

Type:

Methods


add(entry)

Inserts an entry in the model.

Parameters:
Name Type Description
entry *

The object to register in the model.

Throws:

ReferenceError if the entry in argument is 'null' or 'undefined'.


addAt(index, entry)

Inserts an entry in the model at a specific position index.

Parameters:
Name Type Description
index number

The index position to register the object.

entry *

The object to register in the model.

Throws:

ReferenceError if the entry in argument is 'null' or 'undefined'.


clear()

Removes all entries register in the model.

Overrides:

clear(index)

Returns the element from this model at the passed index.

Parameters:
Name Type Description
index number

The index of the element to return.

Overrides:
Returns:

The element from this model at the passed index.


has(entry)

Returns true if the model contains the specified entry.

Parameters:
Name Type Description
entry *

The entry reference to check.

Returns:

true if the model contains the specified entry.


isEmpty()

Returns true if this model is empty.

Returns:

true if this model is empty.


notifyAdd()

Notify a signal when a new entry is inserted in the model.


notifyBeforeChange()

Notify a signal before the specified value is changed.

Inherited From:

notifyChange()

Notify a signal when the model is changed.

Inherited From:

notifyClear()

Notify a signal when the model is cleared.

Inherited From:

notifyRemove()

Notify a signal when a new entry is removed in the model.


notifyUpdate()

Notify a signal when a new entry is updated in the model.


remove(entry)

Removes an entry in the model.

Parameters:
Name Type Description
entry *

The object to unregister in the model.


removeAt(id [, count])

Removes from this model all the elements that are contained between the specific id position and the end of this list (optional operation).

Parameters:
Name Type Argument Default Description
id number

The index of the element or the first element to remove.

count number <optional>
1

The number of elements to remove (default 1).

Returns:

The Array representation of all elements removed in the original list.


removeRange(fromIndex, toIndex)

Removes from this model all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive.

Shifts any succeeding elements to the left (reduces their index).

This call shortens the model by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

Parameters:
Name Type Description
fromIndex number

The from index (inclusive) to remove elements in the list.

toIndex number

The to index (exclusive) to remove elements in the list.


setArray(ar)

Enforce to set the internal array of this model (default use a new Array instance). This method change the model without notification.

Parameters:
Name Type Description
ar array

The Array reference to fill the model.


toArray()

Returns the internal array representation of this model.

Returns:

The array representation of this model.


updateAt(index, entry)

Update an entry in the model with the specified index.

Parameters:
Name Type Description
index number

The index to update an entry.

entry *

the new value to insert in the model at the specified index.