The Base Array class is designed for MVC(Model-View-Controller).
Although the class name contains "Array", but this is not Javascript Array class.
If you need to modify an element, use insertAt()
, setAt()
and removeAt()
methods.
The benefit of this class is you are able to catch the events that occurs when you change the value.
The below examples are how to use this class.
var mvcArray = new plugin.google.maps.BaseArrayClass();
// Catch the insert_at event when you insert new value to the mvcArray each time.
mvcArray.on("insert_at", function(index) {
console.log("---> [insert_at] position : " + index + ", value : " + this.getAt(index));
});
// Catch the set_at event when you change an element with new value.
mvcArray.on("set_at", function(index, oldValue) {
console.log("---> [set_at] position : " + index + ", value : " + this.getAt(index));
});
// Catch the remove_at event when you delete an element from the mvcArray each time.
mvcArray.on("remove_at", function(index, oldValue) {
console.log("---> [remove_at] position : " + index + ", value : " + oldValue);
});
mvcArray.push("A"); // ---> [insert_at] position : 0, value : "A"
mvcArray.push("B"); // ---> [insert_at] position : 1, value : "B"
mvcArray.push("C"); // ---> [insert_at] position : 2, value : "C"
mvcArray.pop() // ---> [remove_at] position : 2, value : "C"
mvcArray.setAt(2, "D"); // ---> [set_at] position : 1, value : "B"
console.log(mvcArray.getArray()); // "A", "D"
This class extends BaseClass.
BaseArrayClass(array?:Array) | A mutable MVC Array. |
---|
empty() | Removes all elements from the array. |
---|---|
forEach() | Iterate over each element, calling the provided callback. This method provides two ways:
|
map() | Iterate over each element, calling the provided callback. Then you can get the results of each callback. This method provides two ways:
|
getArray() | Returns a reference to the underlying Array. |
getAt(i:number) | Returns the element at the specified index. |
insertAt(i:number, elem:*) | Inserts an element at the specified index. |
pop() | Removes the last element of the array and returns that element. |
push(elem:*) | Adds one element to the end of the array and returns the new length of the array. |
removeAt(i:number) | Removes an element from the specified index. |
setAt(i:number, elem:*) | Sets an element at the specified index. |
forEach(fn) | Iterate `fn` in synchro. |
forEachAsync(fn, callback) | Iterate `fn` in asynchro. |
filter(fn) | Filter values in synchro. |
filterAsync(fn, callback) | Filter values in asynchro. |
map(fn) | Map values in synchro. |
mapAsync(fn, callback) | Map values in asynchro. |
mapSeries(fn, callback) | Map values in asynchro, but keep the iterate order. |
insert_at | Arguments: number This event is fired when insertAt() is called. The event passes the index that was passed to insertAt(). |
---|---|
remove_at | Arguments: number, * This event is fired when removeAt() is called. The event passes the index that was passed to removeAt() and the element that was removed from the array. |
set_at | Arguments: number, * This event is fired when setAt() is called. The event passes the index that was passed to setAt() and the element that was previously in the array at that index. |