Methods
(static) cancelAnimationFrame(id)
清除动画延时
Example
import {requestAnimationFrame, cancelAnimationFrame} from '$ui/utils/util'
const id = requestAnimationFrame(()= > {
// do sth
})
cancelAnimationFrame(id)
Parameters:
Name | Type | Description |
---|---|---|
id |
number | 标识 |
(static) cloneDeep(value) → {*}
深拷贝
Parameters:
Name | Type | Description |
---|---|---|
value |
* | 要深拷贝的值 |
Returns:
返回拷贝后的值
- Type
- *
(static) debounce(fn, delayopt, isImmediateopt, contextopt) → {function}
防抖函数
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | 事件处理函数 |
||
delay |
number |
<optional> |
20
|
延迟时间 |
isImmediate |
boolean |
<optional> |
false
|
是否立刻执行 |
context |
object |
<optional> |
this
|
上下文对象 |
Returns:
事件处理函数
- Type
- function
(static) get(object, path, defaultValueopt) → {undefined|*}
根据path查找对象或数组中的某个属性
Example
import {get} from '$ui/utils/util'
const object = { 'a': [{ 'b': { 'c': 3 } }] };
get(object, 'a[0].b.c') // -> 3
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
object |
object | array | 要检索的对象 |
|
path |
string | array | 要获取属性的路径 |
|
defaultValue |
string |
<optional> |
如果解析值是 undefined ,这值会被返回。 |
Returns:
- Type
- undefined | *
(static) grouping(data, fieldopt) → {object}
对数组按制定字段名称进行分组
Example
[{name:1, group:'a'},{name:2, group:'a'}, {name:3, group:'b'}] ->
{
'a':[{name:1, group:'a'}, {name:2, group:'a'}]
'b': [{name:3, group:'b'}]
}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Array | 数组数组 |
||
field |
string |
<optional> |
group
|
分组字段名称 |
Returns:
结果
- Type
- object
(static) guid() → {string}
生成随机GUID
Returns:
- Type
- string
(static) isEqual(object, other) → {boolean}
判断两个对象是否相等
Parameters:
Name | Type | Description |
---|---|---|
object |
* | 对象1 |
other |
* | 对象2 |
Returns:
- Type
- boolean
(static) pager(data, pageopt, sizeopt) → {Array}
分页获取数据
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Array | 源数据 |
||
page |
number |
<optional> |
1
|
当前页面,1开始 |
size |
number |
<optional> |
10
|
页大小,默认10 |
Returns:
- Type
- Array
(static) requestAnimationFrame(callback) → {number}
动画延时函数
Example
import {requestAnimationFrame} from '$ui/utils/util'
requestAnimationFrame(() => {
// do sth ....
})
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | 动画回调函数 |
Returns:
id 标识
- Type
- number
(static) set(object, path, value)
设置 object对象中对应 path 属性路径上的值,如果path不存在,则创建。 缺少的索引属性会创建为数组,而缺少的属性会创建为对象
Parameters:
Name | Type | Description |
---|---|---|
object |
object | 要修改的对象 |
path |
string | array | 要设置的对象路径 |
value |
* | 要设置的值 |
(static) throttle(fn, contextopt, isImmediateopt) → {function}
节流函数
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | 事件处理函数 |
||
context |
object |
<optional> |
this
|
上下文对象 |
isImmediate |
boolean |
<optional> |
false
|
是否立刻执行 |
Returns:
事件处理函数
- Type
- function
(static) uid() → {string}
生成唯一id
Returns:
- Type
- string