列表循环渲染
发布于 6 年前 作者 yanma 5405 次浏览 来自 问答
  • 当前 Bug 的表现(

可附上截图)

  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

列表循环渲染出的MySQL里的数据删除一条,之后最后一条会重复显示,数据库的信息确实删掉了,刷新函数里写onload

onshow函数都没有,提前写了onunload也没有,但是退出后再进入该页面就对了,重复的就没了,类似图中最后两栏重复

Page({

data: {

currentTab: ‘0’,

alltz: [],

alltzsj: [],

allzy:[],

allzysj: []

},

onLoad: function () {

getApp().getstatus()

wx.setNavigationBarTitle({

title: getApp().globalData.gbkcm//页面标题为路由参数

})

},

onShow: function () {

this.getalltz()

this.getalltzsj()

this.getallzy()

this.getallzysj()

},

getalltz: function () {

var that = this;

wx.request({

url: getApp().globalData.gburl +“tz/” + getApp().globalData.gbkcm,

method: ‘GET’,

header: { ‘Accept’: ‘application/json’ },

success: function (res) {

for (var i = 0, len = res.data.length; i < len; i++) {

that.data.alltz[i] = res.data[i];

that.setData({

alltz: that.data.alltz

})

}

}

})

},

getalltzsj: function () {

var that = this;

wx.request({

url: getApp().globalData.gburl +“tzsj/” + getApp().globalData.gbkcm,

method: ‘GET’,

header: { ‘Accept’: ‘application/json’ },

success: function (res) {

for (var i = 0, len = res.data.length; i < len; i++) {

that.data.alltzsj[i] = res.data[i];

that.setData({

alltzsj: that.data.alltzsj

})

}

}

})

},

getallzy: function () {

var that = this;

wx.request({

url: getApp().globalData.gburl +“zy/” + getApp().globalData.gbkcm,

method: ‘GET’,

success: function (res) {

for (var i = 0, len = res.data.length; i < len; i++) {

that.data.allzy[i] = res.data[i];

that.setData({

allzy: that.data.allzy

})

}

}

})

},

getallzysj: function () {

var that = this;

wx.request({

url: getApp().globalData.gburl +“zysj/” + getApp().globalData.gbkcm,

method: ‘GET’,

success: function (res) {

for (var i =res.data.length; i>=0; i–) {

that.data.allzysj[i] = res.data[i];

that.setData({

allzysj: that.data.allzysj

})

}

}

})

},

fbtz:function(){

if (getApp().globalData.gbstatus == 2) {

wx.showToast({

title: ‘暂无该权限’,

icon: ‘none’,

duration: 2000

})

} else {

wx.navigateTo({

url: ‘…/fbtz/fbtz’

})}

},

fbzy: function () {

if (getApp().globalData.gbstatus == 2) {

wx.showToast({

title: ‘暂无该权限’,

icon: ‘none’,

duration: 2000

})

} else {

wx.navigateTo({

url: ‘…/fbzy/fbzy’

})

}

},

sctz: function (e) {

var that=this

var index = parseInt(e.currentTarget.dataset.index);

var time = this.data.alltzsj[index]

wx.showModal({ //使用模态框提示用户进行操作

title: ‘’,

content: ‘删除此通知?’,

success: function (res) {

if (res.confirm) { //判断用户是否点击了确定

if (getApp().globalData.gbstatus== 2) {

wx.showToast({

title: ‘暂无该权限’,

icon: ‘none’,

duration: 2000

})}

else {

wx.request({

url: getApp().globalData.gburl +“sctz/” + time,

method: ‘POST’,

success: function (res) {

if(res.data==1){

wx.showToast({

title: ‘删除成功’,

icon: ‘none’,

duration: 2000

})

}

}

})

}

}

}

})

},

sczy: function (e) {

var that = this

var index = parseInt(e.currentTarget.dataset.index);

var time = this.data.allzysj[index]

wx.showModal({ //使用模态框提示用户进行操作

title: ‘’,

content: ‘删除此项作业?’,

success: function (res) {

if (res.confirm) { //判断用户是否点击了确定

if (getApp().globalData.gbstatus == 2) {

wx.showToast({

title: ‘暂无该权限’,

icon: ‘none’,

duration: 2000

})

}

else {

wx.request({

url: getApp().globalData.gburl +“sczy/” + time,

method: ‘POST’,

success: function (res) {

if (res.data == 1) {

that.onReady();

wx.showToast({

title: ‘删除成功’,

icon: ‘none’,

duration: 2000

})

}

}

})

}

}

}

})

},

bindChange: function (e) {

var that = this;

that.setData({ currentTab: e.detail.current });

},

switchNav: function (e) {

var page = this;

var index = e.target.dataset.current;

if (this.data.currentTab == index) {

return false;

} else {

page.setData({ currentTab: index });

}

},

onPullDownRefresh: function () {

wx.showNavigationBarLoading() //在标题栏中显示加载

this.onShow()     //模拟加载

setTimeout(function () {// complete

wx.hideNavigationBarLoading() //完成停止加载

wx.stopPullDownRefresh() //停止下拉刷新

}, 1500);

}

})

<button class=“bto” bindtap=“fbzy”>+</button>

<view  class=“txh” wx:for = “{{allzy}}” wx:for-item=“item” wx:key="" wx:for-index=“index”  data-index=’{{index}}'bindlongpress=‘sczy’>

<text class=“tsj”>{{allzysj[index]}}</text>

<text class=“tnr”>{{item}}</text>

<view class=“line”></view>

</view>

1 回复

不提供代码片段,猜不到

回到顶部