ht.List(array)

new List(array)

Parameters:
Name Type Attributes Description
array Array.<any> <optional>

Members

length :number

Methods

add(item, index) → {number|Array.<any>}

添加元素

Parameters:
Name Type Attributes Description
item any

元素

index number <optional>

指定位置

Returns:
number | Array.<any> -

返回添加的元素

addAll(array) → {void}

将一批元素加入到当前集合中

Parameters:
Name Type Description
array Array.<any> | ht.List

元素数组或集合

Returns:
void

clear() → {Array.<any>}

清空集合

Returns:
Array.<any> -

返回数组

contains(item) → {boolean}

判断当前集合是否包含参数元素

Parameters:
Name Type Description
item any

是否包含此元素

Returns:
boolean

each(func, scope) → {void}

提供一个回调函数遍历此集合

Parameters:
Name Type Attributes Description
func Object

遍历函数

scope any <optional>

函数域

Returns:
void
Example
list.each(function(item) {
    console.log(item);
});

forEach(func, scope) → {void}

提供一个回调函数遍历此集合

Parameters:
Name Type Attributes Description
func Object

遍历函数

scope any <optional>

函数域

Returns:
void
Example
list.forEach(function(item) {
    console.log(item);
});

get(index) → {any}

返回索引位置的的元素

Parameters:
Name Type Description
index number

索引

Returns:
any -

处于索引位置的元素

getClass() → {function}

获取类声明(构造函数)

Returns:
function -

类声明(构造函数)

getClassName() → {string}

获取类全名

Returns:
string -

类全名

getSuperClass() → {any}

获取父类声明(构造函数)

Returns:
any -

父类声明(构造函数)

indexOf(item) → {number}

获得参数元素的索引

Parameters:
Name Type Description
item any

元素

Returns:
number -

元素的索引

isEmpty() → {boolean}

判断集合是否为空

Returns:
boolean -

集合是否为空

pop() → {any}

删除集合的最后一个元素并返回删除的元素。

Returns:
any -

被删除的元素

push(item) → {void}

向集合的末尾添加一个或多个元素

Parameters:
Name Type Description
item any

元素

Returns:
void

remove(item) → {number}

将参数元素从集合中删除

Parameters:
Name Type Description
item any

要删除的元素

Returns:
number -

要删除的元素的索引

removeAt(index) → {any}

删除索引位置的元素

Parameters:
Name Type Description
index number

要删除的索引

Returns:
any -

删除的元素

reverse() → {void}

将集合中的元素顺序倒序排序

Returns:
void

reverseEach(func, scope) → {void}

提供一个回调函数倒序遍历此集合

Parameters:
Name Type Attributes Description
func Object

遍历函数

scope any <optional>

函数域

Returns:
void
Example
list.reverseEach(function(item) {
    console.log(item);
});

set(index, item) → {any}

设置索引处的元素

Parameters:
Name Type Description
index number

索引,如果此索引处存在元素则将其替换

item any

新元素

Returns:
any

shift() → {any}

删除集合的第一个元素,并返回第一个元素的值。

Returns:
any -

被删除的元素

size() → {number}

获取集合中的元素数

Returns:
number -

集合中的元素数

slice(start, end) → {ht.List}

提取集合中的部分元素组成一个新集合并返回

Parameters:
Name Type Attributes Description
start number

开始索引(包含)

end number <optional>

结束索引(不包含)

Returns:
ht.List -

新集合

sort(sortFunc) → {ht.List}

根据参数函数将元素排序

Parameters:
Name Type Description
sortFunc any

排序函数

Returns:
ht.List -

自身

Example
list.sort(function(item1, item2) {
     returns item1.age > item2.age;
});

toArray(mathFunc, scope) → {Array.<any>}

以matchFunc为过滤函数构建新的元素数组

Parameters:
Name Type Attributes Description
mathFunc Object <optional>
scope any <optional>

函数域

Returns:
Array.<any> -

元素数组

Example
var array = list.toArray(function(item) {
   if (item.a('visible')) {
   	  returns true;
   }
});

toList(mathFunc, scope) → {ht.List}

以matchFunc为过滤函数构建新的元素集合

Parameters:
Name Type Attributes Description
mathFunc Object <optional>
scope any <optional>

函数域

Returns:
ht.List -

元素集合

Example
var list = list.toList(function(item) {
    if (item.a('visible')) {
        returns true;
    }
});

toString() → {string}

重写js默认的toString

Returns:
string

unshift(item) → {void}

向数组的开头添加一个或更多元素

Parameters:
Name Type Description
item any

元素

Returns:
void