微信小程式修改資料不重新整理頁面更新資料
阿新 • • 發佈:2018-12-31
先將資料儲存到本地快取,如下:
wx.setStorageSync('caseid', this.data.id)
wx.setStorageSync('newmsg', data) //data是一個物件
在需要修改的頁面獲取本地快取的資料,如下:
var newmsg = wx.getStorageSync('newmsg')
var caseid = wx.getStorageSync('caseid')
將獲取到的本地快取資料通過對比ID判斷更改哪一個列表的資料,如下:
let list = this.data.anliList;//這裡是將需要迴圈的陣列賦值給list // 將本地快取資料渲染到對應修改的案例 list.forEach(function (value,index, array){ console.log(array[index].id) if (array[index].id == caseid) { array[index].cover = newmsg.cover; array[index].name = newmsg.name; array[index].tags = newmsg.tags; array[index].color = newmsg.color; array[index].price = newmsg.price; console.log(array[index].cover) console.log(array[index].name) } }) this.setData({ anliList: list })