Array&Tree,flat,groupBy,uniq

ArrayService

Used for conversion and access between arrays and trees. It is generally used with nz-tree.

You can override ArrayService to set the mapping name through Global Configuration.

treeToArr

Convert tree structure to array structure.

PropertyDescriptionTypeDefault
deepMapNameDeep map namestringdeep
parentMapNameParent item map name of flat arraystringparent
childrenMapNameSource data children map namestringchildren
clearChildrenWhether remove children itembooleantrue
cbCallback event(item: any, parent: any, deep: number) => void-

arrToTree

Convert array structure to tree structure.

If parent_id is a string, the root value Make Sure is an empty string.

PropertyDescriptionTypeDefault
idMapNameId map namestringid
parentIdMapNameParent id map namestringparent_id
rootParentIdValueRoot parent id value, the most suitable root parent id value will be automatically calculated by defaultany-
childrenMapNameChildren map namestringchildren
cbCallback event(item: any) => void-

arrToTreeNode

Convert array structure to nz-tree data structure.

PropertyDescriptionTypeDefault
idMapNameId map namestringid
parentIdMapNameParent id map namestringparent_id
titleMapNameTitle map namestringtitle
isLeafMapNameisLeaf map name, if value does not exist, include children value to determine whether it's a leaf nodestringisLeaf
checkedMapnameChecked map namestringchecked
selectedMapnameSelected map namestringselected
expandedMapnameExpanded map name (Except leaf nodes)stringexpanded
disabledMapnameDisabled map namestringdisabled
cbCallback event(item: any, parent: any, deep: number) => void-

visitTree

Recursive access tree.

PropertyDescriptionTypeDefault
childrenMapNameChildren map namestringchildren

findTree

Return the value of the first tree value in the tree where predicate is true, and undefined otherwise.

PropertyDescriptionTypeDefault
childrenMapNameChildren map namestringchildren

getKeysByTreeNode

Get all the selected key values.

PropertyDescriptionTypeDefault
includeHalfCheckedWhether include half-checkedbooleantrue
keyMapNameWhether re-specify key namestring-
cbCallback event, return key value(item: NzTreeNode, parent: NzTreeNode, deep: number) => any-

flat

Recursively flattens array.

srv.flat([1, [2, 3, [4, 5, [6]]]]) => [1,2,3,4,5,6]
srv.flat([1, [2, 3, [4, 5, [6]]]], 1) => [1,2,3,[4, 5, [6]]]

groupBy

Group the array.

srv.groupBy([6.1, 4.2, 6.3], Math.floor) => {"4":[4.2],"6":[6.1,6.3]}
srv.groupBy(['one', 'two', 'three'], v => v.length) => {"3":["one","two"],"5":["three"]}

uniq

Creates a duplicate-free version of an array.

uniq([1, 2, 2, 3, 1]) => [1,2,3]
uniq([{ a: 1 }, { a: 1 }, { a: 2 }], 'a') => [{"a":1},{"a":2}]
uniq([{ a: 1 }, { a: 1 }, { a: 2 }], i => (i.a === 1 ? 'a' : 'b')) => [{"a":1},{"a":2}]