utility.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const formatDate = function(date) {
return moment(date).format("YYYY-MM-DD HH:mm:ss")
}
const getPagedList = function(list, columnNum) {
const baseArray = list
const len = baseArray.length
const lineNum = len % columnNum === 0 ? len / columnNum : Math.floor((len / columnNum) + 1)
let result = []
for (let i = 0; i < lineNum; i++)
{
// slice() 方法返回一个从开始到结束(不包括结束)选择的数组的一部分浅拷贝到一个新数组对象。且原始数组不会被修改。
const temp = baseArray.slice(i * columnNum, i * columnNum + columnNum)
result.push(temp)
}
return result
}
const isEqual = (value, other) => {
return _.isEqual(value, other)
}
const isOneOfTheseValue = function(value, expectedValueList) {
for (let expectedValue of expectedValueList)
{
if (isEqual(value, expectedValue))
{
return true
}
}
return false
}
const filterEmptyValueInObject = function(object) {
for (let key in object)
{
let value = object[key]
if (isOneOfTheseValue(value, ['', NaN, undefined, null]))
{
delete object[key]
}
}
return object
}