两个元素换位子;
function swapArr(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
}
置顶移动
function toFirst(fieldData,index) {
if(index!=0){
// fieldData[index] = fieldData.splice(0, 1, fieldData[index])[0]; 这种方法是与另一个元素交换了位子,
fieldData.unshift(fieldData.splice(index , 1)[0]);
}
}
向上移动一格
function upGo(fieldData,index){
if(index!=0){
fieldData[index] = fieldData.splice(index-1, 1, fieldData[index])[0];
}else{
fieldData.push(fieldData.shift());
}
}
向下移动一格
function downGo(fieldData,index) {
if(index!=fieldData.length-1){
fieldData[index] = fieldData.splice(index+1, 1, fieldData[index])[0];
}else{
fieldData.unshift( fieldData.splice(index,1)[0]);
}
}
具体例子见https://www.cnblogs.com/huihuihero/p/10921507.html
中的“动态添加一组可编辑框”