Collection

创建Collection实例

关系

Extends

Collection Extends Evented

继承: Evented

构造函数

属性

declaredClass

声明的类名

declaredClass: string

类型: string

destroyed

指示对象是否已被销毁

destroyed: boolean

类型: boolean

initialized

指示对象是否已初始化

initialized: boolean

类型: boolean

length

集合中项目的数量

length: number

类型: number

方法

add

添加单个项目到集合

add(item, index?): this

参数

  • item: T 要添加的项目
  • index?: number 插入位置,如果不指定则添加到末尾

返回:this

addHandles

添加事件句柄到指定组

addHandles(handles, groupKey?): void

参数

  • handles: IHandle | IHandle 要添加的句柄或句柄数组
  • groupKey?: Exclude<T> 组标识键

返回:void

addMany

批量添加多个项目到集合

addMany(items, index?): this

参数

  • items: Collection<T> | T 要添加的项目数组或Collection
  • index?: number 插入位置,如果不指定则添加到末尾

返回:this

at

获取指定索引位置的项目

at(index): T

参数

  • index: number 索引位置

返回:T

clone

创建集合的深度克隆

clone(): Collection

返回:Collection

concat

连接当前集合与另一个数组或集合

concat(value): Collection

参数

  • value: Collection<T> | T 要连接的数组或Collection

返回:Collection

destroy

销毁对象实例

destroy(): void

返回:void

emit

在实例上发射事件

emit(type, event?): boolean

参数

  • type: string 事件名称
  • event?: any 事件载荷数据

返回:boolean

every

测试集合中的所有项目是否都满足条件

every(callback): boolean

参数

返回:boolean

filter

过滤集合项目(类型保护版本)

filter(callback): Collection

参数

  • callback: (item, index, array) => item is S 类型保护函数

返回:Collection

find

查找第一个满足条件的项目

find(callback): T

参数

返回:T

findIndex

查找第一个满足条件项目的索引

findIndex(callback): number

参数

返回:number

flatten

展平集合(相同类型)

flatten(callback): Collection

参数

  • callback: (item, index) => Collection<T> | T 返回数组或Collection的函数

返回:Collection

forEach

遍历集合中的每个项目

forEach(callback): void

参数

返回:void

getItemAt

获取指定索引位置的项目(别名方法)

getItemAt(index): T

参数

  • index: number 索引位置

返回:T

hasEventListener

检查实例是否有匹配指定事件名称的事件监听器

hasEventListener(type): boolean

参数

  • type: string 事件名称

返回:boolean

hasHandles

检查是否存在指定组的句柄

hasHandles(groupKey?): boolean

参数

  • groupKey?: Exclude<T> 组标识键

返回:boolean

includes

检查集合是否包含指定项目

includes(searchElement): boolean

参数

  • searchElement: T 要搜索的项目

返回:boolean

indexOf

查找项目的第一个索引位置

indexOf(searchElement, fromIndex?): number

参数

  • searchElement: T 要搜索的项目
  • fromIndex?: number 开始搜索的索引位置

返回:number

join

将集合项目连接成字符串

join(separator?): string

参数

  • separator?: string 分隔符,默认为逗号

返回:string

lastIndexOf

查找项目的最后一个索引位置

lastIndexOf(searchElement, fromIndex?): number

参数

  • searchElement: T 要搜索的项目
  • fromIndex?: number 开始搜索的索引位置

返回:number

map

映射集合项目到新的Collection

map(callback): Collection

参数

返回:Collection

on

监听添加后事件

on(type, listener): IHandle

参数

返回:IHandle

pop

移除并返回集合的最后一个项目

pop(): T

返回:T

push

添加项目到集合末尾

push(item): number

参数

  • item: T 要添加的项目

返回:number

reduce

从左到右累积集合项目

reduce(callback, initialValue?): R

参数

返回:R

reduceRight

从右到左累积集合项目

reduceRight(callback, initialValue?): R

参数

返回:R

remove

移除指定项目

remove(item): T

参数

  • item: T 要移除的项目

返回:T

removeAll

移除所有项目

removeAll(): T

返回:T

removeAt

移除指定索引位置的项目

removeAt(index): T

参数

  • index: number 索引位置

返回:T

removeHandles

移除指定组的所有句柄

removeHandles(groupKey?): void

参数

  • groupKey?: Exclude<T> 组标识键,如果不指定则移除默认组的句柄

返回:void

removeMany

批量移除多个项目

removeMany(items): T

参数

  • items: Collection<T> | T 要移除的项目数组或Collection

返回:T

reorder

重新排序项目到指定位置

reorder(item, index): T

参数

  • item: T 要重新排序的项目
  • index: number 目标位置

返回:T

reverse

反转集合中项目的顺序

reverse(): this

返回:this

set

设置单个属性值

set(propertyName, value): this

参数

  • propertyName: string T 属性名称 ###### value 属性值

返回:this

shift

移除并返回集合的第一个项目

shift(): T

返回:T

slice

提取集合的一部分作为新Collection

slice(begin?, end?): Collection

参数

  • begin?: number 开始索引
  • end?: number 结束索引(不包含)

返回:Collection

some

测试集合中是否至少有一个项目满足条件

some(callback): boolean

参数

返回:boolean

sort

对集合项目进行排序

sort(compareFunction?): this

参数

返回:this

splice

在指定位置删除和/或添加项目

splice(start, deleteCount, ...items): T

参数

  • start: number 开始位置
  • deleteCount: number 要删除的项目数量
  • items: ...T 要添加的项目

返回:T

toArray

将集合转换为普通数组

toArray(): T

返回:T

unshift

在集合开头添加一个或多个项目

unshift(...items): number

参数

  • items: ...T 要添加的项目

返回:number

watch

监听属性变化

watch(path, callback, sync?): WatchHandle

参数

  • path: string | string 要监听的属性路径,可以是字符串或字符串数组
  • callback: WatchCallback 属性变化时的回调函数
  • sync?: boolean 是否同步执行回调,默认为false

返回:WatchHandle

new ofType

new ofType(items?): Collection

参数

返回:Collection构造函数

BIMFlux AI