FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Webclient-Store/src/utils/array.ts at typescript · MapGIS/Webclient-Store · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
MapGIS
/
Webclient-Store
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
16
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Webclient-Store
/
src
/
utils
/
array.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (27 loc) · 1.12 KB
Breadcrumbs
Webclient-Store
/
src
/
utils
/
array.ts
Copy path
File metadata and controls
27 lines (27 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
*
@param
arr 数组
*
@param
index 移动的下标
*
@param
tindex 要移动到的新下标
*/
export
function
moveArray
(
arr
,
index
,
tindex
)
{
if
(
tindex
<
0
||
tindex
>=
arr
.
length
)
{
return
arr
;
}
if
(
index
<
0
||
index
>=
arr
.
length
)
{
return
arr
;
}
// 如果当前元素在拖动目标位置的下方,先将当前元素从数组拿出,数组长度-1,
// 我们直接给数组拖动目标位置的地方新增一个和当前元素值一样的元素,
// 我们再把数组之前的那个拖动的元素删除掉,所以要len+1
if
(
index
>
tindex
)
{
arr
.
splice
(
tindex
,
0
,
arr
[
index
]
)
;
arr
.
splice
(
index
+
1
,
1
)
}
else
{
// 如果当前元素在拖动目标位置的上方,先将当前元素从数组拿出,数组长度-1,
// 我们直接给数组拖动目标位置+1的地方新增一个和当前元素值一样的元素,
// 这时,数组len不变,我们再把数组之前的那个拖动的元素删除掉,下标还是index
arr
.
splice
(
tindex
+
1
,
0
,
arr
[
index
]
)
;
arr
.
splice
(
index
,
1
)
}
return
arr
;
}
Back
|
FazBrowse Home
|
New Git URL