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