//编辑--取出指定下标并跳转到编辑页面toRemake:function(){    var questions = [];    questions = wx.getStorageSync('questions');    var index = this.data.idx;    var question = questions[index];    var qType = question.type;    if(qType==='单选'){      wx.navigateTo({        url: '../single/single?idx='+this.data.idx,      })    }else if(qType==='多选'){      wx.navigateTo({        url: '../check/check?idx=' + this.data.idx,      })    }else{      wx.navigateTo({        url: '../input/input?idx=' + this.data.idx,      })    }     },//删除指定下标的元素,重新保存数组,并刷新页面  toDelete:function(){    var questions = wx.getStorageSync('questions');    var index = this.data.idx;    questions.splice(index, 1);    wx.setStorageSync("questions", questions);    wx.redirectTo({      url: '../lookServey/lookServey',    })  },  //上移并刷新页面和下移并刷新页面  toChange:function(){    var questions = this.data.questions;   if(this.data.idx===0){     wx.showToast({       title: '已经在第一位了',       icon:"none"     })   }else{     this.changeUp(questions, this.data.idx);     wx.setStorageSync("questions", questions);     wx.redirectTo({       url: '../lookServey/lookServey',     })   }      },  toChange1: function () {    var questions = this.data.questions;if(this.data.idx===questions.length-1){  wx.showToast({    title: '已经在最后一位了',    icon:'none'  })}else{  this.changeDown(questions, this.data.idx);  wx.setStorageSync("questions", questions);  wx.redirectTo({    url: '../lookServey/lookServey',  })}     },//上移方法  changeUp: function(arr, index){    var temp;    if(index===0 || index arr.length - 1) {      return arr;    }    temp = arr[index];    arr[index] = arr[index - 1];    arr[index - 1] = temp;    return arr;   },

//下移方法

 changeDown: function (arr, index) {

   var temp;    if (index === arr.length-1) {      return arr;    }    temp = arr[index];    arr[index] = arr[index +1];    arr[index + 1] = temp;    return arr;  },

TAG标签: 微信小程序数组删除

http://www.xiaochengxub.com/read-105119.html