new List()
集合类,提供比原生数组更便捷的API
Methods
-
add(item, index)
-
增加元素
Parameters:
Name Type Argument Description item
Object 新元素
index
Number <optional>
插入索引
-
addAll(array)
-
将一批元素加入到当前集合中
Parameters:
Name Type Description array
Array | ht.List 元素数组或集合
-
clear()
-
清空集合
-
contains(item)
-
判断当前集合是否包含参数元素
Parameters:
Name Type Description item
Object 是否包含此元素
-
each(func, scope)
-
提供一个回调函数遍历此集合
Parameters:
Name Type Argument Description func
function 遍历函数
scope
Object <optional>
函数域
Example
list.each(function(item) { console.log(item); });
-
get(index) → {Object}
-
返回索引位置的的元素
Parameters:
Name Type Description index
Number 索引
Returns:
处于索引位置的元素
- Type
- Object
-
getClass() → {function}
-
获取类声明(构造函数)
Returns:
类声明(构造函数)
- Type
- function
-
getClassName() → {String}
-
获取类全名
Returns:
类全名
- Type
- String
-
getSuperClass() → {function}
-
获取父类声明(构造函数)
Returns:
父类声明(构造函数)
- Type
- function
-
indexOf(item) → {Number}
-
获得参数元素的索引
Parameters:
Name Type Description item
Object 元素
Returns:
元素的索引
- Type
- Number
-
isEmpty() → {Boolean}
-
判断集合是否为空
Returns:
集合是否为空
- Type
- Boolean
-
remove(item) → {Number}
-
将参数元素从集合中删除
Parameters:
Name Type Description item
Object 要删除的元素
Returns:
要删除的元素的索引
- Type
- Number
-
removeAt(index) → {Ojbect}
-
删除索引位置的元素
Parameters:
Name Type Description index
Number 要删除的索引
Returns:
删除的元素
- Type
- Ojbect
-
reverse()
-
将集合中的元素顺序倒序排序
-
reverseEach(func, scope)
-
提供一个回调函数倒序遍历此集合
Parameters:
Name Type Argument Description func
function 遍历函数
scope
Object <optional>
函数域
Example
list.reverseEach(function(item) { console.log(item); });
-
set(index, item)
-
设置索引处的元素
Parameters:
Name Type Description index
Number 索引,如果此索引处存在元素则将其替换
item
Object 新元素
-
size() → {Number}
-
获取集合中的元素数
Returns:
集合中的元素数
- Type
- Number
-
slice(start, end) → {ht.List}
-
提取集合中的部分元素组成一个新集合并返回
Parameters:
Name Type Description start
Number 开始索引(包含)
end
Number 结束索引(不包含)
Returns:
新集合
- Type
- ht.List
-
sort(sortFunc) → {ht.List}
-
根据参数函数将元素排序
Parameters:
Name Type Description sortFunc
function 排序函数
Returns:
自身
- Type
- ht.List
Example
list.sort(function(item1, item2) { return item1.age > item2.age; });
-
toArray(matchFunc, scope) → {Array}
-
以matchFunc为过滤函数构建新的元素数组
Parameters:
Name Type Argument Description matchFunc
function <optional>
过滤函数
scope
Object <optional>
函数域
Returns:
元素数组
- Type
- Array
Example
var array = list.toArray(function(item) { if (item.a('visible')) { return true; } });
-
toList(matchFunc, scope) → {ht.List}
-
以matchFunc为过滤函数构建新的元素集合
Parameters:
Name Type Argument Description matchFunc
function <optional>
过滤函数
scope
Object <optional>
函数域
Returns:
元素集合
- Type
- ht.List
Example
var list = list.toList(function(item) { if (item.a('visible')) { return true; } });
-
toString() → {String}
-
重写js默认的toString
Returns:
- Type
- String