[项目]小程序数组操作(上移下移编辑删除)
//编辑--取出指定下标并跳转到编辑页面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; },声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

