//删除指定下标的元素,重新保存数组,并刷新页面
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; },













